```ts type ValueMap = { type1: string; type2: number; } interface ItemType<Type extends "ty

type ValueMap = {
    type1: string;
    type2: number;
}

interface ItemType<Type extends "type1" | "type2"> {
    type: Type;
    value: ValueMap[Type];
}

declare const itemType: ItemType<"type1" | "type2">;

if (itemType.type === "type1") {
  itemType.value; // string | number still
}
Was this page helpful?