10

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?

2 Answers 2

7

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!

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

Comments

0

Don't change the extension of this file. Just add the reference of your custom definition inside this file using the triple slash notation :

/// <reference path="./your-custom-typing.d.ts">

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.