Re:Fast and precise type checking for JavaScript
by curryhoward on Thursday November 09, 2017 @12:03AM
(#15660015)
Just as an example, this program type checks in TypeScript but crashes at runtime:
`f(h);` would be a type error if function types were contravariant in their argument types. TypeScript made the unsound choice to let function types be bivariant in their argument types, which the authors claim is justified for practical reasons. More info here: https://github.com/Microsoft/TypeScript/wiki/FAQ#why-are-fun...
[ Parent
| on HN ]
Re:Fast and precise type checking for JavaScript
by besquared on Thursday November 09, 2017 @12:28AM
(#15660114)
They added contravariant functions in 2.6 using the compiler flag --strictFunctionTypes as described in this PR https://github.com/Microsoft/TypeScript/pull/18654