I will do this step by step with explanations, so it may seem long, but according to the instructions that must be followed, it only takes a few minutes .
Imagine the following project structure:
proj/
├─ tsconfig.json
└─ src/
└─ ...
Create a local folder in the root of your project.
It does not matter what he called, but we will call him local-types. You can change it to whatever you want if you have a good understanding of what we have done here.
proj/
├─ tsconfig.json
├─ local-types/
└─ src/
└─ ...
types.
tsconfig.json.
- ( Node)
baseUrl- (..
paths) typeRoots
tsconfig.json :
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"strict": true,
"outDir": "./dist",
"moduleResolution": "node",
"baseUrl": "./",
"paths": {
"*": ["local-types/*"]
},
"typeRoots": [
"node_modules/@types",
"node_modules/",
"local-types"
]
},
"include": [
"src"
]
}
:
baseUrl - , paths. , local-types/* ./local-types/*.paths local-types.typeRoots " ". , Node Mocha.
.
foo, foo index.d.ts:
export function hello(): void;
export function world(): void;
:
proj/
├─ tsconfig.json
├─ local-types/
| └─ foo/
| └─ index.d.ts
└─ src/
└─ ...
foo `src.
import { hello, world } from "foo";
hello();
world();
, index.d.ts. , npm.
DefinitelyTyped
.d.ts ? , pull DefinitelyTyped, !
, .