VS代码资源管理器:仅隐藏生成的.d.ts文件



在VS代码管理器中,我想隐藏TypeScript编译期间生成的文件。

当具有my-file.ts时,生成的文件可以是:

  1. my-file.js
  2. my-file.js.map
  3. my-file.d.ts

隐藏前两个很容易,我需要在VS代码的settings.json中这样做:

{
"files.exclude": {
"**/*.js.map": true,
"**/*.js": { "when": "$(basename).ts" }
}
}

但是第三个呢?我尝试过这个,但它隐藏了所有.d.ts文件,即使是不是从.ts文件生成的独立文件。

{
"files.exclude": {
"**/*.d.ts": { "when": "$(basename).ts", "__MY_PROBLEM": "It hides all .d.ts files" }
}
}

有没有建议只隐藏那些由同名.ts文件生成的.d.ts文件?

您可以用declaration:false关闭.d.ts发射或发射它们进入一个单独的目录:

// tsconfig.json 
"compilerOptions": {
"declaration": true,
"declarationDir": "./types"  // configure the root directory for where declaration files are emitted

对于另一个;隐藏";从v1.64开始生成的文件,请参阅https://stackoverflow.com/a/70748584/836330.

Explorer > Experimental > File Nesting: Patterns设置如下:

*.ts$(capture).js, $(capture).js.map, $(capture).d.ts


我认为不可能隐藏与*.ts文件关联的*.d.ts文件。

请参阅https://github.com/microsoft/vscode/issues/4642一些人报告说这是有效的:

"**/*.map": {
"when": "$(basename)"
}

隐藏*.js.map文件,但我无法获得

"**/*.ts": {
"when": "$(basename)"
}

做任何事情。也许你会有更好的运气。

另请参阅https://github.com/microsoft/vscode/issues/59368不成功的

而且https://github.com/microsoft/vscode/issues/40850谈到了所有CCD_ 18文件都被排除在外的事实。关闭为";超出范围";。但你可以投赞成票。

我在vs代码上使用Explorer Exclude插件。它负责.d.ts文件、.d.ts.map文件以及您要添加的其他文件。

最新更新