0

I'm aware of the VS Code setting named typescript.preferences.autoImportFileExcludePatterns (ref), and my local VS Code is using a recent TypeScript version which support that setting:

enter image description here

Yet I'm not able to prevent VS Code from suggesting to import members from node:test module when writing my test files. For the records I'm using vitest as a test runner, which has typical function names clashing with node:test ones (describe, beforeEach, it).

I tried the following setting, with no luck:

"typescript.preferences.autoImportFileExcludePatterns": ["node:test"],

Of course node-test is not an npm package, so the classic example using "**/node_modules/...some package name..." does not apply here.

Did anyone come into this already?

starball
  • 20,030
  • 7
  • 43
  • 238
superjos
  • 12,189
  • 6
  • 89
  • 134

1 Answers1

0

VS Code added a feature to remember suggestion selections (see Remember suggestion selections #22839). You can see the related commit that completed the issue, and this related file. This is to say- if you set the VS Code setting named editor.suggestSelection to either "recentlyUsed" or "recentlyUsedByPrefix", I think you could get a nice workaround for what you want by just selecting the suggestion you want a couple times.

To get better than that (and actually exclude a specific ambient module declaration from auto import suggestions), I don't think this is easily possible. node:test is an ambient module declaration in node_modules/@types/node/index.d.ts, which is referenced in .node_modules/@types/node/index.d.ts by a /// <reference path="test.d.ts" />, and that index.d.ts file is made part of module resolution by virtue of being specified in the node module's package.json with "types": "index.d.ts". I'm not aware of a feature to exclude module declarations from auto imports, and you don't want to augment the module- you want to make it as if it didn't exist for IntelliSense purposes.

What you could try to do is make your own modified copy of the @types/node package where you edit that index.d.ts file to remove the line that does /// <reference path="test.d.ts" />.

There is a "nuclear" VS Code setting called typescript.preferences.includePackageJsonAutoImports, which I don't think is what you want- using it to disable the node:test import suggestion would also disable the import for the vitest module you want to import.

starball
  • 20,030
  • 7
  • 43
  • 238
  • thanks. I checked if I was already using that `editor.suggestSelection` and I wasn't. Will try with that. – superjos Jul 31 '23 at 07:32