Check out this Codesandbox link to see some code:
type Tags = "TAG1" | "TAG2";
export type S<Tag extends Tags> = {
tag: Tag;
get<K, R>(k: K): R;
};
const store = {
one: "ONE"
};
type Keys = keyof typeof store;
const s: S<"TAG1"> = {
tag: "TAG1",
get<K extends Keys>(k: K) {
return store[k];
}
};
An error occurs with the line:
get<K extends Keys>(k: K) {
The types are incompatible: Type '<K extends "one">(k: K) => { one: string; }[K]' is not assignable to type '<K, R>(k: K) => R'. Types of parameters 'k' and 'k' are incompatible. Type 'K' is not assignable to type '"one"'.ts(2322
Is it possible to pass a key value like this using TypeScript?