Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

189
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!