JSMonk / hegel

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

Incorrect typings warn + phantom variable/type name #126

Closed lifeart closed 4 years ago

lifeart commented 4 years ago

ref https://twitter.com/rage_monk/status/1250109296999829504?s=20

input

let a = 12;
function b(n, m) {
    return n.toString() + m.toString();
}
let c = b(a, a);

output:

image

image

thecotne commented 4 years ago

this is interesting!

in flow and hegel (as i know) you can't have interface that primitive types can implement

for example in typescript you can write this

function b<T extends { toString(): string}>(n: T, m: T): string {
    return n.toString() + m.toString()
}

void b(1, 1);

describing generic with toString that returns string. so that number can be passed here because typescript does not care about number been primitive and not extending object

but in flow and hegel you can't define interface for primitive types because those are nominally typed flow solves this by typing function by usage but. hegel has a design goal not to do that

probably correct solution would be to allow all values to implement interfaces so typescript style generic can be created

JSMonk commented 4 years ago

Fixed in 0.0.43 release. Thank you for the contribution ^_^.