Lose generic when spreading T | undefined
where T is a generic object type
#58645
Labels
Working as Intended
The behavior described is the intended behavior; this is not a bug
π Search Terms
spread, union
π Version & Regression Information
There are 2 problems. The first was changed between versions 4.0.5 and 4.1.5, and the second exists in every version of TS I tried in the Playground.
β― Playground Link
https://www.typescriptlang.org/play/?#code/GYVwdgxgLglg9mABMOcA8AVRBTAHlbMAEwGdE4AjAK22gD4AKKALkSwB9FwjtgYxsRAJSIA3gChEiAE7YoIaUlGIAdGqgAaZKlYAWAEyIAvgG5xR8eNCRYCRBQCG0zDnyFS5arSiMWbRJzcvPyCIhJSsvKKYqrqxmZGQA
π» Code
π Actual behavior
foo
is{ foo: number }
.bar
is{}
.π Expected behavior
foo
is(T & { foo: number }) | { foo: number }
.bar
isT
.Additional information about the issue
I'm not sure if this is same with #58617. But as there are some previous versions of TS work as I expected, I tend to treat it as a different issue and a bug.
The text was updated successfully, but these errors were encountered: