Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

249
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda