how did the kind property get removed from SquareEvent & CircleEvent
type EventConfig<Events extends { kind: string }> = {
[E in Events as E["kind"]]: (event: E) => void;
}
type SquareEvent = { kind: "square", x: number, y: number };
type CircleEvent = { kind: "circle", radius: number };
type Config = EventConfig<SquareEvent | CircleEvent>
// type Config = {
square: (event: SquareEvent) => void;
circle: (event: CircleEvent) => void;
}
btw u can Find this Example code in the Typescript Handbook page 131
You can find it in Typescript Handbook, right after the snippet you posted:
// Remove the 'kind' property
type RemoveKindField<Type> = {
[Property in keyof Type as Exclude<Property, "kind">]: Type[Property]
};
interface Circle {
kind: "circle";
radius: number;
}
type KindlessCircle = RemoveKindField<Circle>;
type KindlessCircle = {
radius: number;
}
https://www.typescriptlang.org/docs/handbook/2/mapped-types.html#key-remapping-via-as