【发布时间】:2019-06-10 14:13:44
【问题描述】:
我有一个带有类型的 npm 包,文件结构类似于以下:
./typings/index.d.ts:
export { ISomeInterface } from './something';
./typings/something.d.ts:
/*
This interface is used by the package internally,
so I can't simply remove the export.
*/
export interface ISomeOtherInterface {
someField: number;
}
export interface ISomeInterface {
someObject: ISomeOtherInterface;
}
./package.json:
"typings": "./typings/index.d.ts"
问题是每当我输入类似的东西时
const a: ISome...
VS Code 的 IntelliSense 向我展示了两个建议:
| Auto import ISomeInterface from 'my-package'
| Auto import ISomeOtherInterface from 'my-package/typings/something'
防止 VS Code 自动提示第二次导入的正确方法是什么?
typescript@3.2.2, VSCode@1.30.2
更新:
library tsconfig(用于为库生成类型的那个):
{
"compilerOptions": {
"target": "es5",
"module": "esnext",
"lib": ["dom", "es2016", "esnext"],
"jsx": "react",
"importHelpers": true,
"strict": true,
"noImplicitAny": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"strictBindCallApply": true,
"strictPropertyInitialization": true,
"noImplicitThis": true,
"alwaysStrict": true,
"noUnusedLocals": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"moduleResolution": "node",
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"declaration": true,
"emitDeclarationOnly": true,
"rootDir": "src",
"outDir": "typings"
},
"include": [
"src/lib/**/*.ts",
"src/lib/**/*.tsx"
],
"exclude": [
"node_modules",
"dist",
"typings",
"src/**/*.spec.ts",
"src/**/*.spec.tsx"
]
}
project tsconfig(使用库的项目中使用的那个):
{
"compilerOptions": {
"target": "es5",
"module": "esnext",
"lib": ["dom", "es2016", "esnext"],
"jsx": "react",
"importHelpers": true,
"strict": true,
"noImplicitAny": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"strictBindCallApply": true,
"alwaysStrict": true,
"noUnusedLocals": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"moduleResolution": "node",
"baseUrl": "./",
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"paths": {
"*": ["node_modules/@types/*", "*"]
}
}
}
【问题讨论】:
-
你能和我们分享你的 tsconfig.json 吗?
-
@Vincenzo 当然,原帖现在包含两个配置
标签: typescript visual-studio-code typescript-typings