Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do i need `typings.json` file in an Angular 2 project?

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.

like image 353
Asim K T Avatar asked Sep 11 '16 04:09

Asim K T


People also ask

What is Typings in Angular?

Typings is an NPM package to handle the type definitions associated with third-party libraries. This way the tooling will be aware of the types used inside the application. After explaining the typings library, Scott summarizes the different coding syntax options with Angular 2.

What is the use of Tsconfig json file in Angular?

A given Angular workspace contains several TypeScript configuration files. At the root tsconfig. json file specifies the base TypeScript and Angular compiler options that all projects in the workspace inherit.

What is Tsconfig json file?

The tsconfig. json file specifies the root files and the compiler options required to compile the project. JavaScript projects can use a jsconfig. json file instead, which acts almost the same but has some JavaScript-related compiler flags enabled by default.

What are .TS files in Angular?

ts: This file is a unit testing file related to app component. This file is used along with other unit tests. It is run from Angular CLI by the command ng test. app.


1 Answers

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.

like image 102
Asim K T Avatar answered Nov 15 '22 18:11

Asim K T