Normally I run tsc -p ./tsconfig.json
which type checks all files in the ./src
folder relative to tsconfig.
But if I run tsc -p ./tsconfig.json src/specific-file.ts
, it complains
error TS5042: Option 'project' cannot be mixed with source files on a command line.
So, if I remove the option and run tsc src/specific-file.ts
then it checks the file, but it does not use any settings from tsconfig (because I haven't specified the tsconfig file?).
How can I run tsc
on a single file and using the settings in tsconfig that would otherwise be used on the whole project?
The tsconfig. json file specifies the root files and the compiler options required to compile the project. JavaScript projects can use a jsconfig. json file instead, which acts almost the same but has some JavaScript-related compiler flags enabled by default.
json file is a file of JSON format which allows us to point the root level files and different compiler options to setup that require to compile a TypeScript based projects. The existence of this file in a project specifies that the given directory is the TypeScript project folder root.
The tsc command envokes the TypeScript compiler. When no command-line options are present, this command looks for the tsconfig. json file. If no tsconfig.
I don't know of a really good solution short of writing your own command-line tool using the TypeScript compiler API. Two easier approaches you might consider:
Write a script that generates a temporary tsconfig.json
file that extends your original tsconfig.json
and sets files
to just the file you want. However, if other files contain global declarations that are needed to type check the file you specified, the other files may not get loaded, so this approach may not work.
Write a script that runs tsc
on the entire project and filters the output as shown in this answer. However, if your concern was performance, this won't help.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With