TypeScript 4.4 Beta
devblogs.microsoft.com
devblogs.microsoft.com
[1] https://docs.racket-lang.org/ts-guide/occurrence-typing.html
https://www.typescriptlang.org/play?ts=4.4.0-beta#code/GYVwd...
Compare to Typed Racket:
#lang typed/racket
(: foo (-> (U String Null) (U String Null) String))
(define (foo a b)
(cond [(and (null? a) (null? b)) "default"]
[(not (null? a)) a]
[#t b]))
Or Psalm, a PHP typechecker I created with occurrence typing:EDIT: What I'd like to see now is a "cleanup" hint, which says: hey I already know what type this is, you can remove these 10 lines of aliasing code in this function.
At least, in the core language itself, not counting extensions (otherwise Haskell).
EDIT:
I will say that it is a pleasant surprise how flexible and practical TypeScript's type system is.
It would seem that the pressure of working for existing untyped programming patterns has produced something that is very usable and unobtrusive.
Except for implicits ha.
Miss it a lot when i have to push some python or golang code.
(but is in fact correct that Java's type system isn't entirely sound, I forget the details, but I believe array element type variance is one of the soundness hole.)