Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

195
Visualizações
Vscode available properties intellisense using javascript or typescript in a function which's parameter is a string

"screenshot of vscode"

Look here.

For the first parameter of the addEventListener function, vscode gives me several inbuilt suggestions

How should I make this available in my javascript function?

It could be using Jsdoc or typescript etc.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can always see what vscode uses for intellisense by hovering on the addEventListener method or ctrl + click to go to the definition in lib.dom.d.ts file where all definitions are present.

By doing the above you will see that the vscode uses the keys of a class called WindowEventMap.

So your function accepting a event listener name could be

function myFunc(event: keyof WindowEventMap): void {
}

A .d.ts file contains typings for java script code. This is how you get typings like the one in your question and from some packages published to npm.

How is your javascript function used by others?

  1. Are you creating a javascript library which will be used by others? Then either use typescript during development and let typescript generate .d.ts files for your code for you. Or If you are not using typescript for development you will have to create your own declarations. And publish your library with these .d.ts file(s). Refer to DefenitelyTyped project for examples.
  2. A file in the same project which uses this function? If you are using typescript like i mentioned in the code snippet above, then intellisense will automatically be shown for users. Else if you are using javascript, then you can still try and create .d.ts files and refer to them in your ts config (Haven't tried this myself).
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda