【发布时间】:2020-09-25 11:03:24
【问题描述】:
tsconfig.json
{
"compilerOptions": {
"baseUrl": "./",
"target": "es6",
"module": "commonjs",
"declaration": true,
"strict": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"typeRoots": [
"node_modules/@types",
"@types"
],
"paths": {
"@types/*": ["@types/*"]
},
},
"exclude": ["node_modules"],
"include": ["./*", "@types"]
}
@types/index.d.ts
import { ExecException } from 'child_process';
type error = ExecException | null;
interface Person {
is: boolean;
str: string;
}
type doThingX = (is: boolean) => boolean;
example.ts
const jon: Person = {
is: 'hello world'
}
const doThing: TdoThing = x => `${x}`;
如果我注释掉导入,则现有类型 - Person 和 doThing 会在 example.ts 中找到并工作 如果我保留对导入的引用,那么它会中断并且 example.ts 无法找到 Person of doThing 的类型。
找不到名称'Person'.ts(2304) 导出的变量 'jon' 已经或正在使用私有名称 'Person'.ts(4025)
找不到名称“TdoThing”.ts(2304) 导出的变量“doThing”已经或正在使用私有名称“TdoThing”。
【问题讨论】:
标签: typescript typescript-declarations