2

I am learning angular2 and was wondering every time I create a new project using angular-cli, there is directory named typings .

I searched for details on internet but couldn't find relevant information with respect to angular2.

Can anyone tell me why typings directory is used inside angular2 project?

what is its exact purpose inside angular2 project?

Bhushan Gadekar
  • 13,485
  • 21
  • 82
  • 131

2 Answers2

1

Typings - TypesScript declaration files.

Quoted from angular.io official website

Many JavaScript libraries such as jQuery, the Jasmine testing library, and Angular itself, 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.

We use TypeScript type definition files — d.ts files — to tell the compiler about the libraries we load.

When including 3rd party libraries, there are two parts... the javascript code you want to execute, and the definition files to give the IDE all it's strongly-typed goodness.

If the lib is not written in Typescript, but some good soul wrote a thirdLib.d.ts definition file for it, you can reference the d.ts file with /// <reference path="thirdLibfolder/thirdLib.d.ts" /> in your ts file. And then still include the actual executing javascript with the script reference as mentioned above.

see here also

Community
  • 1
  • 1
Pardeep Jain
  • 84,110
  • 37
  • 165
  • 215
1

We need to have TypeScript and Typings installed in our workstation. TypeScript is a superset of JavaScript, and works really well with Angular 2.

Typings help TypeScript to identify types for non-typescript code.

typings - This contains files that help TypeScript infer types it is not aware of. Not all JavaScript libraries were written in TypeScript, and for TypeScript to know about them, we'll need these libraries' typings. Those files or libraries are called TypeScript type definition files(d.ts)

micronyks
  • 54,797
  • 15
  • 112
  • 146