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.fromEntries loses all types on the key #49305
I've read the soundness issues discussion on Object.keys(), but I'm not seeing how that should/would apply to Object.fromEntries().
Say if I am passing a [A, B][] into Object.fromEntries() where A is union of a class C and another enum D, I am going to get C.toString() | D. I am already hitting fromEntries(entries: Iterable<readonly any[]>): any; instead.
I just noted that this doesn't work because it's possible to omit a particular row in list, but the resulting type for Object.fromEntries() would generate an object that has all possible Periods as keys.
It wouldn't be correct to do this, because the type of an array tells you want might be in it, not what is in it. For example, list could be entirely empty, which would make object's value be { }, despite the type of object saying that it had a M1 property.
Activity
hfhchan commentedon May 30, 2022
See also: #37457 (comment)
I just noted that this doesn't work because it's possible to omit a particular row in
list, but the resulting type forObject.fromEntries()would generate an object that has all possiblePeriods as keys.Apparently
doesn't work either
hfhchan commentedon May 30, 2022
Essentially a duplicate of #35745 but that issue has been closed without resolution.
RyanCavanaugh commentedon May 31, 2022
It wouldn't be correct to do this, because the type of an array tells you want might be in it, not what is in it. For example,
listcould be entirely empty, which would makeobject's value be{ }, despite the type ofobjectsaying that it had aM1property.typescript-bot commentedon Jun 2, 2022
This issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes.
lbfalvy commentedon Jan 9, 2024
Why not type it as
fromEntries<K, V>(entries: [K, V][]): {[k: K]?: V}?