Reputation: 401
It seems that my typescript compiler is not detecting the DefinedTypes file of the modules when they are in the module (./node_modules//index.d.ts) but detects them in @types folder (./node_modules/@types//index.d.ts).
For example with express-validator, the module comes with its defined type (see: https://github.com/milkeg/testDefinedType/blob/master/node_modules/express-validator/index.d.ts) but when I try to compile using tsc command, I have the following error:
app.ts:5:28 - error TS2307: Cannot find module 'express-validator'.
5 import * as validator from 'express-validator';
My tsconfig.json file is:
{
"compilerOptions": {
"outDir": "./build",
"allowJs": true,
"target": "es2018",
"alwaysStrict": true,
},
"include": [
"./**/*",
],
"exclude": [
"./node_modules/**/*",
"./build/**/*"
],
}
I tried to add "./node_modules/**/*.d.ts" to the include option, but it does not help.
Repo of the example: https://github.com/milkeg/testDefinedType
What should I change to make sure that tsc is taking into account the .d.ts file that are within the module itself (and not only under ./node_modules/@types/*)?
Upvotes: 0
Views: 96
Reputation: 3153
Just add
"typeRoots": [
"./node_modules/@types",
"./path/to/custom/dtsfolder/"
],
to your tsconfig.json
.
Upvotes: 1