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

243
Views
JSDoc multiple key value pair generic

How can I add multiple key value pairs to a function call similar to the way document.createElement works (<K extends keyof HTMLElementTagNameMap>(tagName: K): HTMLElementTagNameMap[K])

This is only so that the JSDoc is properly setup and VSCode intellisense picks up on it and works appropriately.

Map declaration:

export interface KeyMap {
  "A": "true" | "false";
  "B": "a" | "b" | "c";
  "C": "foo" | "bar";
}

Function declaration:

export interface Options {
  [key: keyof KeyMap]: KeyMap[key];
  // It's not working since I don't have a way to refer to the generic type of the key
}

export function test(options: Options);

Calling the function

test({ "A": "true", "C": "bar" });

Since it's on a key and value basis, I don't know how to add a generic so I can later get the possible values for each key.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I fixed it by using { [K in keyof KeyMap]: KeyMap[K]; } and using a type instead of an interface

export type Options = {
  [K in keyof KeyMap]: KeyMap[K];
}
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!