You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Example:
Try an intersection of 2 types where the same property has inconsistent overlapping types:
type Bar = {
Prop: string
};
type Works = Bar & {Prop: number}; // Bar & {Prop: number}
type ThisIsNever = Bar & {Prop: null}; // never
It makes sense to me that individual types can be reduced to never, but why can intersecting types with nested overlapping property types get reduced to never?
This might be expected, but it does feel like a bug to me. My initial use case was joining a few different types together to get a union of all their keys. But since some props had a null | undefined type, it was reduced to never. Causing my use of those keys to fail unexpectedly. I would expect ThisIsNever to have a Prop: never property instead, or maybe a union of string | null. Or at-least surface an error saying the union is not possible because of Prop being incompatible.
Tested on: 4.6.4, 4.7.0-beta
This worked as expected in: v3.8.3. And starts not being expected in v3.9.7
The text was updated successfully, but these errors were encountered:
Conflicting primitives are in the grey zone between conflicting unit types and conflicting object types. It's definitely not possible to produce an intersection of two unit types, definitely is possible to produce an intersection of two object types (or at least it's not computable to determine if any two arbitrary object types have zero overlap), but intersections between two primitives sometimes arise in places that are benign.
This seems to be the source: #31838
Example:
Try an intersection of 2 types where the same property has inconsistent overlapping types:
It makes sense to me that individual types can be reduced to never, but why can intersecting types with nested overlapping property types get reduced to
never
?Playground link: https://www.typescriptlang.org/play?ts=4.7.0-beta#code/C4TwDgpgBAQghgJygXigbwFBW1ACggezAC4oBnYBASwDsBzDAXwG4MMB6dqAdQIQGsyUAGa0IGUJCgBJGsAgIyEAMbAqBGiliIoAMnT4ipGgFcAtgCMFLKJ21J9aQySinL1ieGgA5CADcFWXlFFTUNLXgHA0IXGn9rZlsuSL1oo1d4hEY2O28CYCgIAA9IVQgAE08pbxMAG1qghSVVdU1UFMdnYzramzsAJRUIKgDy40ykqABREtCK0gADDrTYnsYFqAAKPiglnU6Y8YCshYBKKugAVRpyiFE48saQlvD2-ZXSExu7sXK+rkGymGoyOCkmM1K8jGu2WTkOUC+t3uFXWWx2eyicPScWO63OQA
This might be expected, but it does feel like a bug to me. My initial use case was joining a few different types together to get a union of all their keys. But since some props had a
null | undefined
type, it was reduced tonever
. Causing my use of those keys to fail unexpectedly. I would expectThisIsNever
to have aProp: never
property instead, or maybe a union ofstring | null
. Or at-least surface an error saying the union is not possible because ofProp
being incompatible.Tested on: 4.6.4, 4.7.0-beta
This worked as expected in: v3.8.3. And starts not being expected in v3.9.7
The text was updated successfully, but these errors were encountered: