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
I commonly use this pattern to "remove" unnecessary fields from an object in JS:
constfoo={a: 1,b: 2};constbar=Object.assign({},foo,{b: undefined});// Making a copy of 'foo' without field 'b'bar.a=1;// 'bar' should have at least 'a' field here, but TS gives error
🙁 Actual behavior
However, in TS the result of Object.assign was inferred to be of never type. So I got this error:
Property 'a' does not exist on type 'never'.
The intersection '{ a: number; b: number; } & { b: undefined; }' was reduced to 'never' because property 'b' has conflicting types in some constituents.(2339)
Isn't this an error in definition of Object.assign function or in intersection type logic?
🙂 Expected behavior
I expected the result type to be something like { a: number; b?: number; }, { a: number; b: undefined; } or { a: number; }.
The text was updated successfully, but these errors were encountered:
This issue has been marked as 'Question' and has seen no recent activity. It has been automatically closed for house-keeping purposes. If you're still waiting on a response, questions are usually better suited to stackoverflow.
Bug Report
🔎 Search Terms
Object.assign, intersection type, never type, undefined
🕗 Version & Regression Information
⏯ Playground Link
Playground link with relevant code
💻 Code
I commonly use this pattern to "remove" unnecessary fields from an object in JS:
🙁 Actual behavior
However, in TS the result of
Object.assign
was inferred to be ofnever
type. So I got this error:Isn't this an error in definition of
Object.assign
function or in intersection type logic?🙂 Expected behavior
I expected the result type to be something like
{ a: number; b?: number; }
,{ a: number; b: undefined; }
or{ a: number; }
.The text was updated successfully, but these errors were encountered: