JSMonk / hegel

An advanced static type checker
https://hegel.js.org
MIT License
2.09k stars 59 forks source link

Allow function covariance/contravariance #342

Open whzx5byb opened 3 years ago

whzx5byb commented 3 years ago

Playground

var f1: (a: number | string) => undefined = function(){};
var f2: (a: number) => undefined = f1;
// Error: Type "(number | string) => undefined" is incompatible with type "(number) => undefined"
// but it should work.

var f3: () => string = function(){ return '1'};
var f4: () => number | string = f3;
// Error: Type "() => string" is incompatible with type "() => number | string"
// but it should work.