(This is something that's been possible for decades, but it never hit mainstream before as it's hard to implement it well enough to satisfy the silly preferences of us typical programmers :)).
(This is something that's been possible for decades, but it never hit mainstream before as it's hard to implement it well enough to satisfy the silly preferences of us typical programmers :)).
The way sum types are done in TS is really awkward.
The type system is unsound.
What's worse is that you never have a guarantee that the types are actually correct at runtime, due to bad third party typings, compiler limitations, use of any, ...
It's still a lot better than using plain JS, and a lot of the limitations aren't by choice, but come from the need to compile down to and remain compatible with plain JS.
It just could be so much better.
It would hit the sweet spot for me, I know Rust is popular these days, but it seems like it's made for type astronauts, and sometimes I just want to write some code and get things done quickly and don't care about squeezing out every last drop of bare metal performance or abstracting seven layers of types to please a borrow checker.
Or are you wanting a language with different semantics that could be compiled to actual machine code?
There is an example signature at the end of the article; (x: any) => string, this error would not fly if x were unknown.
On of the few remaining scenarios where any might be necessary is to narrow down a generic param, ie <T extends Something<any>>.
Isn't that what ReasonML is for?
I've never seen this as a barrier to producing working software.
Meanwhile Dart is sound, bit but doesn't have nearly the same adoption.
let _: Result<Vec<_>, _> = some_iter.collect();
or like this: let _: Vec<Result<_, _>> = some_iter.collect();
The only thing that has changed here is the type annotation. Both will compile, but the implementation of `collect` is determined by that type. As far as I know this isn't the case in typescript, although please tell me if I'm wrong, I have limited experience from it and I'm thinking more from mypy perspective.This ends up meaning that my types don't drive the program as much. There's this sort of declarative "here's the thing I want, use an implementation of that method to give it to me" that feels very powerful. I miss this a lot with mypy, my type annotations feel very much like annotations, they are a separate part of my program.
If TS were to lean into itself as its own thing, not just a way to do better JS, I think that'd be amazing. I'd love to see an AOT compiled TS where types are a semantic part of the program, I'd love to see it drop `any` entirely as well, and drop support for using JS in TS.
As for soundness, don't care too much tbh.
There's no exact equivalent, but you can use generic functions or function overloads to achieve something similar:
https://www.typescriptlang.org/docs/handbook/2/functions.htm...
Of course it won't select an implementation for you, so you'll have to handle all the possible type combinations yourself in the function body.
Where is this industry and how do I avoid it?
Static typing fell out of favor hard among certain crowds. Typescript brought many of them back to the world of static typing, and all three of the aforementioned languages are getting more static support, so it isn't nearly so prevalent as say 10 or 15 years ago.