We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
interface type coercion type coercion unsatisfied union constraints property missing in but required conditional interference
https://www.typescriptlang.org/play/?#code/JYOwLgpgTgZghgYwgAgILIN4Chm+QZ0gAcAuZARiwF8stRJZEUAhTHPQiU5AJmtvrR4SZMwD6AUQAeYZBBkQQAE3yi2eAsTJ8N8sFDj4yAIgBu0AJ7IEAexsAbY-yxgLRFAGViyALwVkAD68Lm4oAMI2IPgArgC20L5ogcgAFKxB4tJgAJQA3LS2UbIw0SAIiSnZZF5cvgB8yACycGAAFgB0Bso2sZXIDQAM7QCsyAD8vMhk5PmFhNaRMfFQFQDurS0Q5lBkEVFx0Nn1mMg0BYuynESJJWWV+VgA9I-IgKDkyKs2UADW+HQwKSuvh8fnIR2wGjmBygKQwmlqVGy1Dk9nwKAheChy1h8OuiOcz2QgBlyZDwYCorBY6A4oGIoA
interface A { step: 1 } interface B { step: 2 } interface B_Ext extends B { step: 2 extras: "very cool" } type Step = 1 | 2 type Consumer = A | (B | B_Ext); const func = (): Step => Math.random() > 0.5 ? 2 : 1; const consumer = (whatever: Consumer) => { } const step = func(); // ✅ works if(step === 1) { consumer({ step }) } else { consumer({ step }) } // ❌ fails consumer({ step })
The compiler expects that all properties of a sub-constituent be satisfied
The union defines that it is either A | B and B might be B or B & Extras
A | B
B
B & Extras
The same happens with types instead of interfaces as well as a the extras being passed as union of the type:
// causes the same issues type A = { step: 1 } type B = { step: 2 } & ({} | { extras: 'very good' })
The text was updated successfully, but these errors were encountered:
Feels like #57013, or at least related to #30779
Sorry, something went wrong.
No branches or pull requests
🔎 Search Terms
interface type coercion
type coercion
unsatisfied union constraints
property missing in but required
conditional interference
🕗 Version & Regression Information
⏯ Playground Link
https://www.typescriptlang.org/play/?#code/JYOwLgpgTgZghgYwgAgILIN4Chm+QZ0gAcAuZARiwF8stRJZEUAhTHPQiU5AJmtvrR4SZMwD6AUQAeYZBBkQQAE3yi2eAsTJ8N8sFDj4yAIgBu0AJ7IEAexsAbY-yxgLRFAGViyALwVkAD68Lm4oAMI2IPgArgC20L5ogcgAFKxB4tJgAJQA3LS2UbIw0SAIiSnZZF5cvgB8yACycGAAFgB0Bso2sZXIDQAM7QCsyAD8vMhk5PmFhNaRMfFQFQDurS0Q5lBkEVFx0Nn1mMg0BYuynESJJWWV+VgA9I-IgKDkyKs2UADW+HQwKSuvh8fnIR2wGjmBygKQwmlqVGy1Dk9nwKAheChy1h8OuiOcz2QgBlyZDwYCorBY6A4oGIoA
💻 Code
🙁 Actual behavior
The compiler expects that all properties of a sub-constituent be satisfied
🙂 Expected behavior
The union defines that it is either
A | B
andB
might beB
orB & Extras
Additional information about the issue
The same happens with types instead of interfaces as well as a the extras being passed as union of the type:
The text was updated successfully, but these errors were encountered: