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
Iterating through object and assigning to its properties leads to 'never' #38735
Expected behavior:
TraitsSummary and TraitsDetailed have exactly the same keys.
values of props under the keys have matching types so there shouldn't be any error.
Actual behavior:
Type 'string | number' is not assignable to type 'never'.
Type 'string' is not assignable to type 'never'.(2322)
P.S.
I have dozens of errors like Type 'some_type' is not assignable to type 'never'.
All of them happens when I'm trying to assign to object property selected by dynamic key.
I fixed some of issues with generics
(<T, K extends keyof T>(obj: T, keys: K[]) => {
for (let index = 0; index < keys.length; index++) {
const key = keys[index] as keyof T;
filters[key] = null; // or other actions
}
})(obj, originalFields);
But that's not working when you need to map values of one object to another regarding keys are same.
Jack Williams (@jack-williams) Thanks, I'm aware of that change but it didn't give me clear explanation on how to adjust my code to it.
To prevent that code from failing I need a monstrous typescript constructions which decrease a code readability awfully. And sometimes it's just super hard to invent such a construction and I have to put any to save the day.
Activity
jack-williams commentedon May 23, 2020
This behaviour was introduced here #30769, and has lots of relevant discussion.
DzmVasileusky commentedon May 25, 2020
Jack Williams (@jack-williams) Thanks, I'm aware of that change but it didn't give me clear explanation on how to adjust my code to it.
To prevent that code from failing I need a monstrous typescript constructions which decrease a code readability awfully. And sometimes it's just super hard to invent such a construction and I have to put
anyto save the day.typescript-bot commentedon Jun 13, 2020
This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.