Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I specify boolean (true/false) options for TypeScript compiler

Tags:

typescript

tsc

I'm using:

$ tsc --version
Version 2.0.8

and trying to pass --experimentalDecorators option to tsc like this:

$ tsc --experimentalDecorators true greeter.ts
//error TS6053: File 'true.ts' not found.

and like this

$ tsc greeter.ts --experimentalDecorators true
//error TS6053: File 'true.ts' not found.

and like this

$ tsc greeter.ts --experimentalDecorators=true
// error TS5023: Unknown compiler option 'experimentaldecorators=true'.

but no luck. What's the correct way to pass options to tsc?

like image 589
Max Koretskyi Avatar asked May 13 '26 05:05

Max Koretskyi


2 Answers

Currently, the compiler allows passing in explicit boolean values.

There is a strong use case for passing in explicit boolean values to the compiler, when you are compiling against a tsconfig.json and want to override a specific value for the purposes of the current compiler run.

In this case, imagine if your tsconfig.json sets experimentalDecorators to false, and you want to test the compilation when it is true without changing the project itself:

tsc --experimentalDecorators true greeter.ts
like image 160
Zev Spitz Avatar answered May 16 '26 05:05

Zev Spitz


Boolean flags are false by default so you don't need to specify a value along with the flag. You only need to include the flag when you want to change it from false to true.

Remove true:

tsc --experimentalDecorators greeter.ts

For compiler options that expect a string, the value immediately following the argument specifies the argument's value. For example:

tsc --module system greeter.ts

For compiler options that expect an array of strings, the individual string values should be separated by commas:

tsc --lib es5,es6 greeter.ts

The compiler assumes the value passed in is a filename if the value does not match an argument name or is not in the place of an expected argument value.

like image 23
David Sherret Avatar answered May 16 '26 04:05

David Sherret