|
|
|
|
|
by anamexis
770 days ago
|
|
Can you say more about natively supporting discriminated unions? You can already do this: type MyUnion = { type: "foo"; foo: string } | { type: "bar"; bar: string };
And this will compile: (u: MyUnion) => {
switch (u.type) {
case "foo":
return u.foo;
case "bar":
return u.bar;
}
};
Whereas this wont: (u: MyUnion) => {
switch (u.type) {
case "foo":
return u.bar;
case "bar":
return u.foo;
}
};
|
|
You don't need that in a language like F# -- the discrimation occurs strictly in virtue of your union definition. That's what I meant by "native support."