3 ms·
TypeScript doesn't do proper occurrence typing: https://www.typescriptlang.org/play?ts=4.4.0-beta#code/GYVwdgxgLglg9mABMOcAUBDAXIgzlAJxjAHMAfMEAGyoBpEAjHfI0i6q
by muglug 5y ago
TypeScript doesn't do proper occurrence typing:
https://www.typescriptlang.org/play?ts=4.4.0-beta#code/GYVwdgxgLglg9mABMOcAUBDAXIgzlAJxjAHMAfMEAGyoBpEAjHfI0i6qgSmcOJMQDeAWABQicYhjBEmRAF4FiSjUQAyVY3mLlXQaIkHEBAKZQQBJAHIAJseAZqUSwG59EgL6i34qTIyIAQm0OTj0xQ3ETMwtEDFdw8U8RbyNTcyQGePcgA 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:
https://psalm.dev/r/60ef4c299e https://psalm.dev/r/60ef4c299e