未选择 tsconfig.json typeroots 自定义路径 [英] tsconfig.json typeroots custom path not picked up
本文介绍了未选择 tsconfig.json typeroots 自定义路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一些自定义的 .d.ts 文件,我希望 tsc 在编译时选择这些文件.为了完成这项工作,我修改了 tsconfig.file 以包含以下内容
I have some custom .d.ts files and I want tsc to pick up these files when compiling. In order to get this done I modify the tsconfig.file to include the following
"typeRoots": [
"../node_modules/@types",
"./app/modules"
]
./app/modules 是我的自定义 .d.ts 文件所在的位置.在 ./app/modules 文件夹中,我有以下文件 myModule.d.ts
./app/modules is where my custom .d.ts file resides. Inside the ./app/modules folder I have the following file myModule.d.ts
export declare module myModule {
function Login();
function Logout();
}
现在在我的其他打字稿文件中,我有以下导入
Now inside my other typescript file I have the following import
import { myModule } from 'myModule';
这里出现以下错误找不到模块myModule".
推荐答案
我找到了解决此问题的配置.注意 paths
和 baseUrl
属性:
I found the config that fixes this. Note the paths
and baseUrl
properties:
{
"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"]
}
这篇关于未选择 tsconfig.json typeroots 自定义路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文