Replies: 6 comments 19 replies
-
|
How about |
Beta Was this translation helpful? Give feedback.
-
|
Maybe off focused, but clarify, many developers want the TypeScript's flexibility. In typescript, declare funciton like this, function foo(arg: string): void
{
console.log(arg);
}ofcourse, function foo(arg: string | number): void
{
console.log(arg);
}now but, this doesn't illustrate TypeScript's flexibility. TypeScript's function foo(arg: "cat" | -1): 100 | "dog"
{
return arg === "cat" ? 100 : "dog";
// error
//return 500;
//return "animal";
}
if (foo(-1) === 200) { // error because foo never returns 200
}PS. TypeScript has another feature, discriminated union and it's helpful. |
Beta Was this translation helpful? Give feedback.
-
|
Personally I still have reservations about the use of tuple-like syntax for the union types. Everywhere else you see that in C# today (or in most languages) that defines a product type, not a sum type. Is the I really don't understand how a union would have a primary constructor, though. What would you do with that additional state? |
Beta Was this translation helpful? Give feedback.
-
|
What about union Pet =
| Cat
| Dog
| Bird;If we ever want anonymous unions in the future, we could reuse the |
Beta Was this translation helpful? Give feedback.
-
|
I'd like to add |
Beta Was this translation helpful? Give feedback.
-
Do you mind explaining a little more on this point? The two features, while perhaps having some usability overlap, don't seem immediately related so it's not obvious to me why one would be built on the other and they must therefore be developed in series. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
https://github.com/dotnet/csharplang/blob/main/meetings/2025/LDM-2025-09-29.md
Agenda
Beta Was this translation helpful? Give feedback.
All reactions