10

Why do i need typings.json like below:

{
  "globalDependencies": {
    "core-js": "registry:dt/core-js#0.0.0+20160725163759",
    "jasmine": "registry:dt/jasmine#2.2.0+20160621224255",
    "node": "registry:dt/node#6.0.0+20160831021119"
  }
}

for an Angular2 project? I've got:

typings.json provides additional definition files for libraries that the TypeScript compiler doesn't natively recognize.

which, as a newbie I don't clearly understand.

5
  • Than might help: stackoverflow.com/questions/34660265/… Commented Sep 11, 2016 at 4:19
  • Above question is regarding issue with importing modules to the project. I have used npm as the package manager before, So I understood what his issue is. What I didn't understand is why do I need a typings.json in Angular2 projects. Looks like the file maps typescript to an exact version of some third-party libraries. Commented Sep 11, 2016 at 4:28
  • It's not the only way to use typings. General purpose of this file is to tell Typescript that there's something available in global scope from javascript point of view, meaning there will be no errors during execution even if this object is not visible for Typescript at compilation time. Ex: declare var module: { id: string }; means that there's an object module with property id implemented somewhere in plain javascript. Commented Sep 11, 2016 at 4:53
  • 2
    Watch this video. You can start from about 5:00 youtube.com/watch?v=4i1nLrqMR14 Commented Sep 21, 2016 at 2:51
  • Thanks rook. I think I have found why we need typings.json file. Commented Sep 21, 2016 at 5:05

1 Answer 1

6

So, I've found this:

Any JavaScript libraries, such as jQuery, the Jasmine testing library, and Angular, extend the JavaScript environment with features and syntax that the TypeScript compiler doesn't recognize natively. When the compiler doesn't recognize something, it throws an error.

So, If we wrote a library which may use by other persons in their projects along with TypeScript, the TypeScript throws an error. To resolve it, we have to write the TypeScript type definition files (.d.ts files) in the library directory.

AngularJS along with most of the libraries already doing this.But, Libraries like "core-js" and "jasmine" do not include d.ts files in their npm packages. Fortunately, either their authors or community contributors have created separate .d.ts files for these libraries and published them in well-known locations. The typings tool can find and fetch these files for you.

So, we have to write typings.json file to get the correct type definition files to run the project smoothly.

Sign up to request clarification or add additional context in comments.

1 Comment

Note: typings.json is deprecated in favor of @types packages from DefinatelyTyped. See npmjs.com/package/typings

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.