Hacker News new | ask | show | jobs
by SebastianKra 701 days ago
This is the first time I'm hearing such a claim.

In C# you can't work with optional generics because an optional reference type is different from an optional value type.

C#s poor type-inference often requires you to type out types thrice. You can't declare constants or class members with type-inferrence.

The only way to define sum-types (A | B | C) is through intefaces and I'm pretty sure they can't be sealed. Defining product-types (A & B & C) is impossible.

2 comments

Sorry I probably used the wrong term, not a native English speaker. I didn't mean lack of complexity or lack of "features" but rather the lack of carefully thought-through feature "depth". Like, we can infer generic arguments which is nice, but then we try doing that with some keyof complex type and it doesn't work. And later we find an issue on GitHub saying that it's not implemented. Which is fine, I love TS anyway and it's evolving.
C# has record (product) types now.
I'm not sure about the terminology here, but the & in TS is much more than a record. You can use it to smush types together e.g.

{name: string} & {birthday: Date}

becomes a single type with both properties.

Product types are tuple types.

Record types are tuple types with names instead of indexes.

The TypeScript “&” is another thing.