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
Basically I'm using & types as if subclassing. BaseValue has items array with fewer properties, ExtendedValue extends that with items with more properties.
🔎 Search Terms
intersection, ampersand, override, inheritance. Also looked at the titles of first 2 pages of open issues.
🕗 Version & Regression Information
This changed between versions 4.9.5 and 5.0.2
There is an easy work-around, but I'm not sure if it should be necessary.
typeBaseItem={id: number;}typeExtendedItem=BaseItem&{description: string|null};typeBaseValue={// there are other fieldsitems: BaseItem[];}typeExtendedValue=BaseValue&{// there are other fieldsitems: ExtendedItem[];}constTEST_VALUE: ExtendedValue={items: [// ❌ ERROR: This is NOT allowed *iff* mixed types are used in `description`{id: 1,description: null},{id: 2,description: 'wigglytubble'},]};
🙁 Actual behavior
Seems to me like they should be compatible. Also these examples are ✅ allowed in TS 5.0.2 if description only has uniform types, e.g.:
// ✅ Allowed: description has only stringsconstONLY_STRINGS: ExtendedValue={items: [{id: 1,description: 'bollywoggle'},{id: 2,description: 'wigglytubble'},]};// ✅ Allowed: description has only nullsconstONLY_NULLS: ExtendedValue={items: [{id: 1,description: null},{id: 2,description: null},]};
🙂 Expected behavior
Seems like it should be allowed.
🙄 Work-around
Typing ExtendedValue with Omit<> seems to fix the issue with no obvious downsides.
typeExtendedValue=Omit<BaseValue,'items'>&{// there are other fieldsitems: ExtendedItem[];}
The text was updated successfully, but these errors were encountered:
This issue looks to be caused by incomplete propagation of the intersectionState parameter in our type relation logic. I have a fix that I'll put up shortly.
Bug Report
Basically I'm using
&
types as if subclassing.BaseValue
hasitems
array with fewer properties,ExtendedValue
extends that withitems
with more properties.🔎 Search Terms
intersection, ampersand, override, inheritance. Also looked at the titles of first 2 pages of open issues.
🕗 Version & Regression Information
⏯ Playground Link
TypeScript 5.0.2 (error) vs 4.9.5 (OK)
💻 Code
🙁 Actual behavior
Seems to me like they should be compatible. Also these examples are ✅ allowed in TS 5.0.2 if
description
only has uniform types, e.g.:🙂 Expected behavior
Seems like it should be allowed.
🙄 Work-around
Typing
ExtendedValue
withOmit<>
seems to fix the issue with no obvious downsides.The text was updated successfully, but these errors were encountered: