Tsconfig.json typeroots user path not selected

I have some custom .d.ts files and I want tsc to collect these files at compilation. To do this, I modify the tsconfig.file file to include the following

"typeRoots": [ "../node_modules/@types", "./app/modules" ] 

./app/modules is where my custom .d.ts file is. Inside the folder. / app / modules I have the following file myModule.d.ts

 export declare module myModule { function Login(); function Logout(); } 

Now in my other typescript file I have the following import

 import { myModule } from 'myModule'; 

Here I get the following error I can not find the module 'myModule'.

+5
source share
1 answer

I found a configuration that fixes this. Pay attention to the magic of "path" and "baseUrl"

 { "version": "2.1.5", "compilerOptions": { "module": "commonjs", "target": "ES5", "removeComments": true, "preserveConstEnums": true, "inlineSourceMap": true, "lib": [ "es6", "dom" ], "typeRoots": [ "src/subfolder/node_modules/@types" ], "moduleResolution": "node", "baseUrl": "./", "paths": { "*": [ "src/subfolder/node_modules/@types/*", "*" ] } }, "exclude": [ "node_modules", "src/subfolder/node_modules" ] 

}

0
source

Source: https://habr.com/ru/post/1261672/


All Articles