【发布时间】:2017-05-27 00:38:19
【问题描述】:
我正在现有的 JS 项目中设置 TypeScript,我正在尝试弄清楚如何将类型添加到无类型的 npm 模块,因为我知道它会出现。
这一行
import X from 'foo';
Cannot find module 'foo' 出错
在typings/modules 我有一个foo 文件夹,其中包含一个 index.d.ts 文件
declare module foo {
export default class XXX{
}
}
在父 typings/index.d.ts 我已经添加
/// <reference path="modules/foo/index.d.ts" />
但还是一无所获。
我的 tsconfig.json 文件是这样的
{
"compilerOptions": {
"target": "esnext",
"baseUrl": "./src",
"jsx": "react",
"allowSyntheticDefaultImports": true,
"allowJs": true,
"moduleResolution": "node",
"module": "es2015",
"experimentalDecorators": true,
"lib": ["es2015", "dom"],
"typeRoots" : ["./typings/modules", "./node_modules/@types"]
},
"include": [
"./src/**/*.ts",
"./src/**/*.tsx"
]
}
【问题讨论】:
标签: typescript