The union you already write in TypeScript
now compiles in C# 15, with the switch checked.
TYPESCRIPT
type Result = Ok | NotFound;
switch
(result.kind) {
case
'ok'
:
return result.book.title;
case
'notFound'
:
return
'No such book'
; }
C# 15
union Result(Ok, NotFound);
result
switch
{
Ok
ok =>
ok.Book.Title,
NotFound
=>
"No such book"
, };
.NET 11 RC1 ·
no default arm
· a missing case is warning CS8509
gdhami.net