hegel icon indicating copy to clipboard operation
hegel copied to clipboard

Incorrect type inference of strict equality operator

Open leushkin opened this issue 5 years ago • 4 comments

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 avatar May 30 '20 17:05 leushkin

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

leushkin avatar May 30 '20 18:05 leushkin

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.

vkurchatkin avatar May 30 '20 20:05 vkurchatkin

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

leushkin avatar May 31 '20 06:05 leushkin

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

JSMonk avatar Aug 18 '20 02:08 JSMonk