For example we have a discriminated union type:
export type Event =
| {
type: "click";
event: MouseEvent;
}
| {
type: "focus";
event: FocusEvent;
}
| {
type: "keydown";
event: KeyboardEvent;
};
We only wnat to get Discriminator
from it, which is
"click" | "focus" | "keydown"
export type Event =
| {
type: "click";
event: MouseEvent;
}
| {
type: "focus";
event: FocusEvent;
}
| {
type: "keydown";
event: KeyboardEvent;
};
type EventType = Event["type"];
type tests = [Expect<Equal<EventType, "click" | "focus" | "keydown">>];
标签:Typescript,Union,focus,keydown,click,Discriminator,type,event From: https://www.cnblogs.com/Answer1215/p/16974351.html