Anup Vasudeva
Anup Vasudeva

Reputation: 901

Visual Studio Code not recognizing the built-in typescript definition files

I've been trying to create a hello-world sample with TypeScript (1.5 beta) and AngularJS (1.4) using Visual Studio Code (0.3.0) editor. As shown in the snapshot below, when the code references AngularJS' TypeScript definition file, VS Code throws a lot of errors. enter image description here

enter image description here

Not sure what wrong I am doing here.

** Edit ** The typings are installed by first running npm install -g typescript and then tsd install [library-name] --save

Considering the comments from GJSmith3rd, building the project outputs the --help command of tsc. See below: enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

Upvotes: 3

Views: 9822

Answers (1)

GJSmith3rd
GJSmith3rd

Reputation: 816

Typescript in VSCode is working fine with your example.

  1. Create a new folder in VSCode

  2. Create a simple tsconfig.json file with compiler options

    {
        "compilerOptions": {
            "target": "ES3",
            "module": "amd",
            "sourceMap": false
        }
    }
    
  3. Create example code to in app.ts

    export interface IPerson {
        firstName: string;
        lastName: string;
    }
    
    export class Person implements IPerson {
        constructor(public firstName: string, public lastName: string) {
            var module = angular.module("myApp", []);
        }
    }
    
  4. IMPORTANT: Use DefinitelyTyped tsd command $tsd install angular jquery --save from DefinitelyTyped. Angular depends on jQuery.

  5. Add a tsd.d.ts file reference to app.ts

    /// <reference path="typings/tsd.d.ts" />
    
  6. Configure a Task Runner in .settings/tasks.json in directory of the app by using shift+ctl+b and select "Configure Task Runner". Remove the contents of "args:[Hello World], or create a new similar task with "args:[],

  7. Compile with Task Runner with shift+ctl+b

enter image description here

Here's the uncommented task runner I used "args": [],

// A task runner that calls the Typescipt compiler (tsc) and 
// Compiles a app.ts program
{
    "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",

    // args is the app.ts program to compile.
    "args": [],

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

If there are still problems with compiling in VSCode try the command line from the project directory for clues.

tsc --module amd  --out app.js app.ts

and check your version as mentioned earlier:

02:00:23 ツ gjsmith3rd@DV7:~/Workspaces/Examples/TypeScript/MSDN/MyProject5 >tsc --version message TS6029: Version 1.5.3

Consider updating tsc to the latest version which at the time of this edit is v1.5.3 with sudo npm install tsc -g.

Upvotes: 1

Related Questions