Freigeben über


Angular 2 with @types declaration files

- To install TypeScript declarations files, at the beginning you had to install DefinitelyTyped packages using NuGet
- Then the node tool TSD followed and after that came Typings
- The next step in the evolution of type acquisition is @types

- @types only requires npm to be managed
- In enterprise environments, this means one tool less to manage and one proxy setting less to worry about (Typings doesn't use node proxy settings)

- Currently, as of 2016-09-23, the official Angular 2 tutorials use a Typings file to install the declaration files

- To use @types instead:
1. Make sure TypeScript 2 is installed in Visual Studio (if you are using it)
2. Make sure you are using "typescript": "^2.0.3" (or newer) in the package.json file
3. Remove "typings" from "devDependencies" in the package.json file
4. Add the following to "devDependencies":
4a. "@types/core-js": "*"
4b. "@types/node": "*"
4c. If you want to run Jasmine tests, add: "@types/jasmine": "*"
5. Delete the "typings.json" file and "typings" folder
6. Run npm install

- Links:
NPMJS search Type search List of packages and versions

Note: You can also use the @types with specific version numbers, such as "@types/node": "^6.0.42". I only used "*" above for the sake of brevity.

Comments

  • Anonymous
    September 29, 2016
    gold thanks
  • Anonymous
    October 18, 2016
    Hi , I have added @type/node in my devdependencies, still m getting an error "cannot find name require". Can you help me in resolving this issue?
    • Anonymous
      December 09, 2016
      You're missing the "s" ... @types/node