I'm using a tsconfig.json file to specify which typings I want to use in my app.
{
"compilerOptions": {
"types" : ["node", "lodash", "express"]
}
}
This imports typings from ./node_modules/@types/node
, ./node_modules/@types/lodash
and ./node_modules/@types/expres
.
My question is how can I configure typings for self-contained modules?
My example is the zone.js package which has both the library code and type definitions.
What do I put in my tsconfig.json file to include zone.js.d.ts
?
'typeRoots' specifies root folders in which the transpiler should look for type definitions (eg: 'node_modules').
Correct Answer : Option (C) : This file is used to give the options about TypeScript used for the Angular JS project.
with --lib you can specify a list of built-in API declaration groups that you can chose to include in your project. For instance, if you expect your runtime to have support for Map, Set and Promise (e.g. most evergreen browsers today), just include --lib es2015.
You just have to add zone.js
to the types
in your tsconfig.json
:
{
"compilerOptions": {
"types" : ["node", "lodash", "express", "zone.js"]
}
}
Note that you do not have to include all types like this. Type definitions from the @types/*
packages are automatically included.
So you could remove the types declaration in your tsconfig.json
and all the @types/*
packages would be automatically referenced.
In order to get zone.js
to work you can either include it in a single file like this:
/// <reference types="zone.js" />
Or if you want it available in your whole project you can add a index.d.ts
at the root of your project and put int the reference there.
You can place the file anywhere, but you need to tell the compiler about it, either by adding it in tsconfig.json
or as a ///<reference>
. For tsconfig
add the include
field:
{
"compileOnSave": false,
"compilerOptions": {
..
},
"include": [
"zone.d.ts",
]
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With