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
Search Terms:
Type infer array nested interface structure
Code
interfaceValueOnly{value: number|null;}interfaceValueAndKey{key: string|null;value: number|null;}interfaceValueOnlyFields{fields: Array<ValueOnly>;}interfaceValueAndKeyFields{fields: Array<ValueAndKey>;}interfaceBugRepro{dataType: ValueAndKeyFields&ValueOnlyFields;}interfaceBugReproWithoutArray{dataType: ValueAndKey&ValueOnly;}// This. Having the "key" errors out because of extra "key" field,// while not having the "key" makes it complain that "key" is missing.constrepro: BugRepro={dataType: {fields: [{key: 'bla',value: null,}],}}// Without nesting the type inside of an array, it can infer the type nicely.constreproWithoutArray: BugReproWithoutArray={dataType: {key: 'bla',value: null,},}
Expected behavior:
Compiler should not complain that "key" is defined.
Actual behavior:
Compiler cannot identify that the array is neither Array, and Array without me casting it.
TypeScript Version: 3.3.333
Search Terms:
Type infer array nested interface structure
Code
Expected behavior:
Compiler should not complain that "key" is defined.
Actual behavior:
Compiler cannot identify that the array is neither Array, and Array without me casting it.
Playground Link:
https://www.typescriptlang.org/play/#src=interface%20ValueOnly%20%7B%0D%0A%20%20value%3A%20number%20%7C%20null%3B%0D%0A%7D%0D%0A%0D%0Ainterface%20ValueAndKey%20%7B%0D%0A%20%20key%3A%20string%20%7C%20null%3B%0D%0A%20%20value%3A%20number%20%7C%20null%3B%0D%0A%7D%0D%0A%0D%0Ainterface%20ValueOnlyFields%20%7B%0D%0A%20%20fields%3A%20Array%3CValueOnly%3E%3B%0D%0A%7D%0D%0A%0D%0Ainterface%20ValueAndKeyFields%20%7B%0D%0A%20%20fields%3A%20Array%3CValueAndKey%3E%3B%0D%0A%7D%0D%0A%0D%0Ainterface%20BugRepro%20%7B%0D%0A%20%20dataType%3A%20ValueAndKeyFields%20%26%20ValueOnlyFields%3B%0D%0A%7D%0D%0A%0D%0Ainterface%20BugReproWithoutArray%20%7B%0D%0A%20%20dataType%3A%20ValueAndKey%20%26%20ValueOnly%3B%0D%0A%7D%0D%0A%0D%0A%2F%2F%20This.%20Having%20the%20%22key%22%20errors%20out%20because%20of%20extra%20%22key%22%20field%2C%0D%0A%2F%2F%20while%20not%20having%20the%20%22key%22%20makes%20it%20complain%20that%20%22key%22%20is%20missing.%0D%0Aconst%20repro%3A%20BugRepro%20%3D%20%7B%0D%0A%20%20dataType%3A%20%7B%0D%0A%20%20%20%20fields%3A%20%5B%7B%0D%0A%20%20%20%20%20%20key%3A%20'bla'%2C%0D%0A%20%20%20%20%20%20value%3A%20null%2C%0D%0A%20%20%20%20%7D%5D%2C%0D%0A%20%20%7D%0D%0A%7D%0D%0A%0D%0Aconst%20reproWithoutArray%3A%20BugReproWithoutArray%20%3D%20%7B%0D%0A%20%20dataType%3A%20%7B%0D%0A%20%20%20%20key%3A%20'bla'%2C%0D%0A%20%20%20%20value%3A%20null%2C%0D%0A%20%20%7D%2C%0D%0A%7D%0D%0A%0D%0A
Related Issues:
Couldn't find.