Is there a way to include multiple key-value pairs in a function call similar to the setup of document.createElement
(
<K extends keyof HTMLElementTagNameMap>(tagName: K): HTMLElementTagNameMap[K]
)?
This is specifically for proper JSDoc configuration and so that VSCode intellisense functions correctly.
Defined Map:
export interface KeyMap {
"A": "true" | "false";
"B": "a" | "b" | "c";
"C": "foo" | "bar";
}
Function Definition:
export interface Options {
[key: keyof KeyMap]: KeyMap[key];
// I'm facing issues as there isn't a method to reference the generic type of the key
}
export function test(options: Options);
Using the Function:
test({ "A": "true", "C": "bar" });
Due to the structure being based on key-value pairs, it's challenging to incorporate generics and retrieve potential values for each key later on.