JSMonk / hegel

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

Incorrect type inference of strict equality operator #263

Open leushkin opened 4 years ago

leushkin commented 4 years ago

https://hegel.js.org/try#GYVwdgxgLglg9mABDAzgUQLYAcoE8DKUATjGAOYAUAhgJSIDeAUIi8sItYgLw+IDkfOk1YjERAKZQQRJMRDjmrAL6NFLCVJmJgVADYoFKxhAQooydNjzcLmHAWKlKfABbjduuIKA

The a parameter should be considered as a string.

PS probably for not strict equality there is also a bug

leushkin commented 4 years ago

I think that a bug is here at 181 line. I tried to fix it like that: if refinementedVariants has length of 1, then it is not a union, so refinementedType should be subtype of refinementedVariants[0]. But it didn't work :(

Screenshot 2020-05-30 at 20 57 55
vkurchatkin commented 4 years ago

This has nothing to do with refinement, it is an inference bug. This yields the same error.

function isEmptyString(a) {
    a === '';
}

const isEmpty = isEmptyString('hello')

In reality a shouldn't even be inferred as string, it should be unknown or unconstrained generic.

leushkin commented 4 years ago

Ops yep you are right, my fault, I'm going to rename the issue

JSMonk commented 4 years ago

It will be fixed in the next release. Thank you for the issue. You are awesome :3