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
Object literal array type inconsistently inferred when using spread #30761
constarray1=[{a: 'a',b: 'b'},{a: 'a',c: 'c'},]// inferred: Partial<{ a, b, c }>[]array1.map(({ c })=>c);// works ✅constarray2=[{a: 'a',b: 'b'},{a: 'a', ...{c: 'c'}},]array2.map(({ c })=>c);// suddenly error? ❌
Expected behavior:
I'm not sure if this is a bug but I expect both map calls to type-check identically. If it's not a bug, it's very unintuitive why the spread syntax completely changes how the array type is inferred. The only workaround I have is to explicitly write the full type (which isn't as concise as the example above).
Is the special logic documented somewhere? It would help avoid surprises and confusion if the logic is more explicitly defined, or if there are ways to control the inference.
Activity
RyanCavanaugh commentedon Apr 10, 2019
We have "special" logic for unifying object literals in these cases; the spread syntax interferes with that.
If you post a more representative sample where it's not just spreading for the sake of spreading, we may be able to advise more.
ssynix commentedon Apr 10, 2019
Here's almost the same code that reproduces the error.
Is the special logic documented somewhere? It would help avoid surprises and confusion if the logic is more explicitly defined, or if there are ways to control the inference.