Naeem Sarfraz Naeem Sarfraz - 1 month ago 13
TypeScript Question

What is the correct tasks.json config for compiling typescript in Visual Studio Code?

Using

Ctrl
+
Shift
+
B
I added a default tasks.json file and uncommented the second task runner block. I have a typescript file in the root of the directory and a tsconfig.json.

Everytime I compile I get 'error TS5023: Unknown compiler option 'p'. What is the correct definition to allow me to compile a typescript file? Can all files be compiled in one go even if they are in subdirectories?

I have tried changing the args below to
["${file}"]
which simply allows me to compile the file that is open. This works. I've also run the tsc command from the command prompt and no -p or -project arguments exists.

tasks.json

{
"version": "0.1.0",

// The command is tsc. Assumes that tsc has been installed using npm install -g typescript
"command": "tsc",

// The command is a shell script
"isShellCommand": true,

// Show the output window only if unrecognized errors occur.
"showOutput": "silent",

// Tell the tsc compiler to use the tsconfig.json from the open folder.
"args": ["-p", "."],

// use the standard tsc problem matcher to find compile problems
// in the output.
"problemMatcher": "$tsc"
}


tsconfig.json

{
"compilerOptions": {
"target": "ES5",
"module": "amd",
"sourceMap": true
}
}


VS Code: v0.30

TypeScript: v1.4

Answer

I had the same problem. It was a wrong PATH variable to the TypeScript compiler. (try to type tsc -v in a command window). The tsconfig.json is supported in TypeScript version 1.5. My PATH variable was set to version 1. When I changed the system PATH variable to the updated installation folder (C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.5) and a restart of Visual Studio Code, everything was fine. (Remove all entries from the args!) Like:

{
    "version": "0.1.0",

    // The command is tsc. Assumes that tsc has been installed using npm install -g typescript
    "command": "tsc",

    // The command is a shell script
    "isShellCommand": true,

    // Show the output window only if unrecognized errors occur. 
    "showOutput": "always",

    // Tell the tsc compiler to use the tsconfig.json from the open folder.
    "args": [],

    // use the standard tsc problem matcher to find compile problems
    // in the output.
    "problemMatcher": "$tsc"
}