Open eilvelia opened 4 years ago
A similar (not the same though) thing happens if we try to change a class generic based on method's type parameters;
class HttpRequest<D = unknown> {
data: unknown = null;
setData<T>(data: T): HttpRequest<T> {
this.data = data;
return this;
}
}
const req = new HttpRequest();
const result = req.setData(5);
Here, result
's type is unknown where we would expect it to be number.
I'm not sure if this is related as there is no error thrown but the inference is off, we can create an additional issue if that'd be more appropriate.
Oh, right, it's another bug, related to inferencing this
type.
Thank you a lot guys (@anacierdem and @Bannerets) for providing this information.
Also, seems like all bugs like this will be fixed in the second version of Hegel.
The type inference doesn't seem to work when a method returns an instance of the class whose type parameter depends on the method's type parameters. E.g:
This errors with
It works correctly in Flow and TypeScript.
Can be fixed if
f1.map<string>(
is written manually.Interestingly, if I replace
with
then it will work, even though the inferred return type of
map
is stillFunctor<U>
.try hegel