-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Generic type gets widened in an unexpected way #52249
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
In ts 5.0 you can just write See #51865 for details. |
@whzx5byb It's indeed better but:
Adding another weird case and easier one (again works for union and not const e = <T>(value: T): {a: T} => ({a: value});
const g = e(v); // Gets widened
const e2 = <T>(value: T): T => value;
const g2 = e2(v); // Works |
The widening behavior is intended, see #10676. And if you want to preserve the type alias you can just add |
With all respect to the new Considering |
I’m pretty sure that |
That's exactly what I am doing though... |
I'd agree something weird appears to be happening here. A demonstration is to slightly tweak these definitions const b = <T>(fn: null | ((value: T) => T), v: T): T => fn!(v);
const r1 = b(null, v); // SomethingOne, as expected The call of |
Bug Report
🔎 Search Terms
widen
🕗 Version & Regression Information
4.9.4
⏯ Playground Link
Playground link with relevant code
💻 Code
🙁 Actual behavior
The type gets widened when using
BooleanMapToUnion
... I guess it is the culprit.🙂 Expected behavior
Both union and using
BooleanMapToUnion
should work equally.The text was updated successfully, but these errors were encountered: