d79c37cd19
* Discriminate contextual types * Invert conditional * Update findMatchingDiscriminantType and baselines
26 lines
368 B
TypeScript
26 lines
368 B
TypeScript
// @noImplicitAny: true
|
|
type ADT = {
|
|
kind: "a",
|
|
method(x: string): number;
|
|
} | {
|
|
kind: "b",
|
|
method(x: number): string;
|
|
};
|
|
|
|
|
|
function invoke(item: ADT) {
|
|
if (item.kind === "a") {
|
|
item.method("");
|
|
}
|
|
else {
|
|
item.method(42);
|
|
}
|
|
}
|
|
|
|
invoke({
|
|
kind: "a",
|
|
method(a) {
|
|
return +a;
|
|
}
|
|
});
|