3 ms·
TypeScript and, AFAIK, Kotlin provide exactly that. The problem with that special syntax sugar is that then there's no monad to compose with. But it does feel
by sabellito 6y ago
TypeScript and, AFAIK, Kotlin provide exactly that.
The problem with that special syntax sugar is that then there's no monad to compose with. But it does feel nice for many use cases.
- int_19h 6y agoTypeScript also uses union types for null & undefined. But then on top of that, it has optionals. So you can have: function foo(x: number | undefined); or you can have: function foo(x?: number); The type of x inside foo is the same in both cases, but the type of foo differs. The first version can only be called as foo(x) - where x is possibly undefined - but the second one can also be invoked as foo(), which then has the same meaning as foo(undefined). But this is mostly because they were trying to come up with a type system to capture existing JavaScript patterns. I doubt it'd look like that if it could be designed from scratch.