-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Type 'T' is not assignable to type 'T extends Sub ? Sub : T'. #48746
Comments
Any recommendations on how to express this differently that doesn't run into this problem? Perhaps there is a way to express the join/meet operation without conditionals. |
FWIW I tried using |
interface Base {
base: unknown;
}
interface Sub extends Base {
sub: unknown;
}
function transform<T extends Base>(t: T extends Sub ? T & Sub : T): T extends Sub ? Sub : T {
return t;
}
var t = transform({base: 0, foo: 0})
// ^? var t: { base: number, foo: number }
var sub = transform({base: 0, sub: 0, foo: 0})
// ^? var sub: Sub I don't know why |
Maybe syntax-driven? Would make sense. |
This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
Bug Report
π Search Terms
variance, conditional, subtype, limit
π Version & Regression Information
β― Playground Link
Playground link with relevant code
π» Code
π Actual behavior
"Type 'T' is not assignable to type 'T extends Sub ? Sub : T'."
π Expected behavior
No errors. Either T extends Sub, and so is assignable to it, or it doesn't, and so is assignable to itself.
The text was updated successfully, but these errors were encountered: