【发布时间】:2018-08-30 16:04:55
【问题描述】:
我试图只有一个文件来包含将在整个应用程序中使用的大部分类型定义,我创建了一个名为 @types 的文件夹和一个导出每个接口的 index.d.ts 文件/输入我想要的。
更新了我的 tsconfig.json 以包含该文件夹:
{
"compilerOptions": {
"outDir": "./built",
"allowJs": true,
"target": "es5",
"jsx": "react",
"allowSyntheticDefaultImports": true,
"lib": [
"es2015"
],
"typeRoots": [
"./@types"
],
},
"include": [
"./client/**/*",
"./@types/**/*"
],
"awesomeTypescriptLoaderOptions": {
"silent": true,
"errorsAsWarnings": true
}
}
即使在代码中(在客户端/...内)我引用 index.d.ts 上存在的接口之一时,vscode 仍会抛出“找不到名称”。
有没有更好的方法来解决这个问题?
@types/index.d.ts 中存在接口定义。
export interface Agent {
name: string;
...
}
用法:
interface Props extends RouteComponentProps<any> {
agent?: types.Agent;
}
【问题讨论】:
-
请将代码(声明和引用)添加到问题中。
-
@MattMcCutchen 定义+用法已添加。
标签: typescript visual-studio-code