我有一个随输入附带的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
UPD:
库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/*", "*"]
}
}
}