Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to include typescript custom type definitions in angular 2?

I don't understand how custom type definitions files are included in typescript applications. For example, this application has src/custom-typings.d.ts file that contains custom type definitions. How this file is included?

I tried to rename this file and it is included anyway. The file extension can be *.ts (not only *.d.ts). Does webpack search type definitions in every *.ts file in the project? If so, then how to change this behavior? How to tell webpack to search type definitions in a specific file?

like image 217
Ildar Avatar asked Jul 09 '16 21:07

Ildar


1 Answers

Well it's not Webpack who search for the *.ts unless you are not using the ts-loaders. There are many libraries based on Javascript like lodash, if you wish to use them in you angular2 project and you are using typescript for development then you have to use typings.

What is typings?

read the answer here

how to load .d.ts file in your project? for example if you are using angular2 then there are some dependecies you have to use like zone if you wish to add zone to your app you can simply do

import "zone.js/dist/zone";

and it look for the d.ts file and load it for you.

I load my dependencies like this

import "core-js";
import "zone.js/dist/zone";
import "reflect-metadata";
import "es6-shim";

if you look into node_modules/reflect-metadata it contain reflect-metadata.d.ts file

I hope i could explain and it will help you!

like image 134
Jorawar Singh Avatar answered Sep 28 '22 14:09

Jorawar Singh