S M
S M

Reputation: 3233

Why we use tsconfig.json is Visual studio 2015?

I am unclear about tsconfig.json, even when I am not using it also I am able to compile the angular2 typescript application. But in Angular site it is given to configure typescript we need to add a tsconfig.json file to the project folder. Can somebody help me explain this. I have searched a lot but in vain.

Upvotes: 3

Views: 2242

Answers (1)

SnareChops
SnareChops

Reputation: 13347

The tsconfig.json file is a configuration file for tsc the typescript compiler as you have stated. The file is not required but recommended. This is because the TypeScript compiler uses default compiler options when building a project, but usually those aren't enough.

The TypeScript compiler can also use command line arguments (the same arguments in the tsconfig.json file) to set the options that you would like. Again these are not required, but are recommended to mold the compilation in the way that you would like for your project.

It is also possible that your IDE (Visual Studio) is setting some of these options for you, and could also have a configuration screen that when the compiler is triggered it passes these options along with it.

TypeScript however is a generic solution that works outside of VS as well. Therefor providing the options in a tsconfig.json would allow the compilation to work outside of VS and even on other OS like OSX or Linux.

An example of a compiler option that is not a default, but is required by angular is...

"experimentalDecorators": true

or, on the command line...

--experimentalDecorators

This allows the @Component and other decorators to be correctly outputted in JS. This feature is not turned on by default and therefor is needed to be sent to the compiler somehow, either through command line, tsconfig.json or other method.

Upvotes: 6

Related Questions