TypeScript: Specify a directory to search for module type definitions
Heyho,
I want to use some javascript libraries in my typescript code for which there is no typing in npm. So I wrote the typing myself and put them in a directory definitions
in the source tree. However, I could not get typescript to search this directory for these modules.
My directory structure looks like this:
+-node_modules
| |
| +-moduleA
| |
| +-moduleB
|
+-src
| |
| +-definitions
| | |
| | +-moduleA.d.ts
| | |
| | +-moduleB.d.ts
| |
| +-ts
| |
| + ... all typescript code ...
|
+-tsconfig.json
I tried to include modules in the directory definitions
using
-
include
-
files
-
typeRoots
-
paths
However, none of this worked.
Can anyone tell me how to get typescript to enable these typings?
PS: Why does the typescript module work so hard?
source to share
You can enable them with triple slash directives to direct the compiler to use them.
eg. create a file index.d.ts
and place it in the definitions folder. There you can enable every custom text input you have made. It might look like this.
/// <reference path="react.patch.d.ts" />
/// <reference path="custom-typings.d.ts" />
Inside the typing file, the first line should be
/// <reference types="nameOfIt" />
Then in yours tsconfig.json
you include them in a box files
, for example.
"files": [
"definitions/index.d.ts"
]
source to share