Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Typescript compile on save is not working when tsconfig.json is in project

I can't make visual studio to run typescript compilation to js when I save.

enter image description here

I have an xproj (asp.net core with net framework) TypeScript 2.0.3 tools for Visual studio 2015 update 3.

I have tried to enable "watch" : true in tsconfig.json but it says that current host is not supported.

I went to Tools > Options > Text Editor > TypeScript > Project and enabled "automatically compile TypeScript files which are not part of project"

enter image description here

Still, changes in .ts files will be reflected in .js files only during compilation, but only when there are changes in c# sever-side files that has to be compiled.

EDIT: I have figured out that simple existance of tsconfig.json in the project directory will prevent compilation on save even if the config file is empty.

Can that be fixed somehow currently?

This is the content of my tsconfig.json:

{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "moduleResolution": "node",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "removeComments": false,
    "noImplicitAny": false,
    "diagnostics": true
  },
  "include": [
    "**/*.ts"
  ],
  "exclude": [
    "node_modules"
  ]
}

EDIT 2: I also tried:

{
  "compileOnSave": true,
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "moduleResolution": "node",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "removeComments": false,
    "noImplicitAny": false,
    "diagnostics": true
  },
  "filesGlob": [
    "**/*.ts"
  ],
  "exclude": [
    "node_modules"
  ]
}

and it didn't do anything.

like image 766
doker Avatar asked Sep 26 '16 11:09

doker


People also ask

What is the use of Tsconfig JSON file in TypeScript?

The presence of a tsconfig. json file in a directory indicates that the directory is the root of a TypeScript project. The tsconfig. json file specifies the root files and the compiler options required to compile the project.

Does tsc use Tsconfig?

Running tsc locally will compile the closest project defined by a tsconfig. json , you can compile a set of TypeScript files by passing in a glob of files you want.


2 Answers

I uninstalled Visual Studio 2015 and Typescript 2.0.3. Then I reinstalled Visual Studio 2015. After opening my solution and checked Typescript 1.8.3, I installed Typescript 2.0.3 and added "compileOnSave" before "compilerOptions". Since then it works for me. You need to restart Visual Studio after adding this option.

{
  "compileOnSave": true,
  "compilerOptions": {
  ...
}
like image 136
Bluesight Avatar answered Oct 02 '22 14:10

Bluesight


Adding "compileOnSave":true to tsconfig.json should do the trick:

{
  "compileOnSave": true,
  "compilerOptions": {
  ...
like image 36
Aleksey L. Avatar answered Oct 02 '22 12:10

Aleksey L.