如何在 VS Code / TypeScript 中禁用过多的自动导入建议?

Dan*_*hov 9 typescript visual-studio-code typescript-typings

我有一个带有类型的 npm 包,文件结构类似于以下内容:

./typings/index.d.ts

export { ISomeInterface } from './something';
Run Code Online (Sandbox Code Playgroud)

./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;
}
Run Code Online (Sandbox Code Playgroud)

./package.json

"typings": "./typings/index.d.ts"
Run Code Online (Sandbox Code Playgroud)

问题是每当我输入类似

const a: ISome...
Run Code Online (Sandbox Code Playgroud)

VS Code 的 IntelliSense 向我展示了两个建议:

| Auto import ISomeInterface from 'my-package'
| Auto import ISomeOtherInterface from 'my-package/typings/something'
Run Code Online (Sandbox Code Playgroud)

防止 VS Code 自动建议第二次导入的正确方法是什么?

打字稿@3.2.2,VSCode@1.30.2

更新:

库 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"
  ]
}
Run Code Online (Sandbox Code Playgroud)

项目 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/*", "*"]
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

Sha*_*ory 0

我能想到的有两件事。

  1. 在第一个 tsconfig 中,尝试将 outFile 设置为 index.d.ts。它应该只生成 1 个声明文件。

  2. 尝试从第二个 tsconfig 中删除它

"paths": {
  "*": ["node_modules/@types/*", "*"]
}
Run Code Online (Sandbox Code Playgroud)