Thorsten Westheider Thorsten Westheider - 3 months ago 42
TypeScript Question

Why does Typescript ignore my tsconfig.json inside Visual Studio Code?

I got my project setup like this

project/
|
+---src/
| |
| +---app/
| |
| sample.ts
|
+---typings/
+---tsconfig.json


and here's my
tsconfig.json


{
"compilerOptions": {
"rootDir": "src",
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": true,
"sourceMap": true,
"noImplicitAny": false,
"outDir": "dist"
},
"exclude": [
"node_modules",
"src/assets",
"src/lib"
]
}


What I'm wondering is, why does VSC indicate errors such as

Error Highlighting in VSC

when clearly there is no error at all (
"experimentalDecorators": true
is set in
tsconfig.json
), and the app transpiles just fine? And it's not just decorators,
Promise
and the like is highlighted as well (I made sure to have
tsconfig.json
in the same folder as
typings
and I got the typings for
es6-shim
installed).

Not sure if it matters, but I'm on
typescript@2.0.0-dev.20160707
at the moment.

Answer

Locate the folder typescript was installed to by npm, in my case this was

C:\Users\<username>\AppData\Roaming\npm\node_modules\typescript\\lib

Among other files, there should be

lib.d.ts
tsserver.js

inside. Now open settings

File -> Preferences -> User Settings/Workspace Settings

This should open a file settings.json, add

{
    "typescript.tsdk": "C:\\Users\\<username>\\AppData\\Roaming\\npm\\node_modules\\typescript\\lib"
}

(mind the double backslashes \\), save and - important - restart Visual Studio Code. Enjoy.

Comments