Home > Software engineering >  How do I add global types to eslint/emmet in vscode?
How do I add global types to eslint/emmet in vscode?

Time:12-19

NOTE: This is NOT a typescript question. I'm using JavaScript, not TypeScript

ESLint/Emmet in VSCode is aware of certain global types. For example: I type

const ctx = AudioC

And vscode/eslint/emmet auto completes it to AudioContext.

enter image description here

And if I continue and type

  const ctx = new AudioContext();
  ctx.create

it clearly knows the type since it provides completions for that type, not just that it's a global

enter image description here

How do I add new global completions/type data? For example these types

enter image description here

Note: I'm not asking about /* global someName */ nor am I asking about enter image description here

I didn't have to add any special comments or annotations to the file. the types are added at a global level.

CodePudding user response:

The enter image description here

See VSCode docs: https://code.visualstudio.com/docs/nodejs/working-with-javascript

This doesn't help eslint. It still complains. But you can manually add them to your .eslintrc file. For this particular file I extracted them with

grep "declare var" ./node_modules/@webgpu/types/dist/index.d.ts | sed 's/declare var \(.*\):.*$/"\1",/'

If there is an more standard way to get eslint to recognize those globals please add an answer.

  • Related