Closed
Description
Bug Report
π Search Terms
spread assignment generic constraint
π Version & Regression Information
version 4.3.0-dev.20210418
version 4.3.0-beta
- This changed between versions 4.2 and 4.3
β― Playground Link
π» Code
type A = { kind: "a" };
type B = { kind: "b" };
type Component = A | B;
function rebuild<T extends Component>(c: T): T {
const newC: T = { // <------- error: cannot assign
...c
};
return newC;
}
π Actual behavior
Type '{ kind: "a"; } | { kind: "b"; }' is not assignable to type 'T'.
'{ kind: "a"; } | { kind: "b"; }' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Component'.
Type '{ kind: "a"; }' is not assignable to type 'T'.
'{ kind: "a"; }' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Component'.(2322)
π Expected behavior
No error, since c
is T
, { ... c }
should also be T
.
Activity
MartinJohns commentedon Apr 21, 2021
Duplicate of #43749.