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
The value {fields: null} is not assignable to type {fields?: string}. Optional properties can be undefined, not null. Is this a mistake?
Object.assign() produces an intersection type, which is only an approximation of what happens when there is property overlap, see Bug Report + Proposal: Object.assign() #31982 for why.
Since Reduce intersections by discriminants #36696, the intersection that comes out of Object.assign() here, {fields: null} & ({ fields?: string , strict?: boolean} | undefined), will be reduced to never. Apparently the reduction to never here makes the compiler forget about any control flow narrowing for options, and it resets to the original type of options, which includes undefined in its domain. When you make any of the changes you mention above, this reduction to never doesn't happen, because there's no longer an impossible discriminant type.
This is a combination of things working as intended and known design limitations. If you think there's something here that isn't explained by the above points, could you point it out?
Bug Report
With the strict null check turned on
Any of the following changes fix the first (but not the second):
🔎 Search Terms
strictNullCheck, Object.assign
🕗 Version & Regression Information
4.1.3
⏯ Playground Link
https://www.typescriptlang.org/play?#code/GYVwdgxgLglg9mABFApgZygCjgB1gtAfgC5EBvRYGFAGwBMjSMAnGMAcwBpEWZoTEAIzhwaKAIZIAvgEpyAKERLEufGDSIAvIgDyggFYpoAOnFo0MdmEwUqtBqTAgaNRFO6r46mQG5FymGBEbDwvNGM7ejQ5Mn9lZQB6BIA9VLTk3QMjKEQYDRw4cxhBGgBPRABycDoUKjAUOgrjKDRMACYAVgBmNpk4t36IAhzUDDatYLlNAD4FePmAoJC1cN5oGP6FhaT0tMzDaFz8wosS8qqwGrqGppb27t7Nral+l6kgA
💻 Code
🙁 Actual behavior
Wrongly assumes the
options
can be undefined🙂 Expected behavior
Should be no error
The text was updated successfully, but these errors were encountered: