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
{{ message }}
Repository navigation
Type narrowing for object literal being defined and returned in place behaves differently with variable indirectionΒ #43966
interfaceOrange{name: string;}interfaceApple{name: string;}functiontest<TextendsApple|Orange>(item: T): T{// fails with: '{ name: string; }' is assignable to the constraint of type 'T', but 'T' could be instantiated with// a different subtype of constraint 'Orange | Apple'.(2322)return{...item};}functiontest2<TextendsApple|Orange>(item: T): T{constx={...item};// this works due to the indirection w/ a variable declaration resolving the type to `T`returnx;}
π Actual behavior
TypeScript behaves inconsistently when the instance is cloned using spread operator, depending on
whether the spread operator is used in an object literal as variable initializer, or as direct value for a return statement.
π Expected behavior
TypeScript should narrow the type consistently; so that no errors are reported inconsistently.
Activity
sandersn commentedon May 7, 2021
Broken by #43183
refactor(compiler-cli): remove unecessary type assertion
refactor(compiler-cli): remove unecessary type assertion (#49971)
refactor(compiler-cli): remove unecessary type assertion (#49971)