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
interfaceEmptyInterface{};typeStringRecord=Record<string,string>;interfaceInterfaceextendsStringRecord{};typeEIFKey=keyofEmptyInterface// nevertypeSRKey=keyofStringRecord// stringtypeIFKey=keyofInterface// number | string, why not string?
π Actual behavior
IFKey is number | string
π Expected behavior
IFKey should be string
The text was updated successfully, but these errors were encountered:
nicky1038
changed the title
keyof interface is inferred incorrectly when interface extends Record<string, any>
keyof infers type incorrectly when it is applied to interface that extends Record<string, any>
Sep 11, 2023
nicky1038
changed the title
keyof infers type incorrectly when it is applied to interface that extends Record<string, any>
"keyof" infers type incorrectly when it is applied to interface that extends Record<string, any>
Sep 11, 2023
I believe the difference in behavior comes down to, Record is implemented as a mapped type. keyof MappedTypeOverString is string. Interfaces canβt be mapped types though (AFAIK), so extending a Record<string, T> demotes it to an index signature, and keyof StringIndexSignatureType is string | number, by design.
Uh oh!
There was an error while loading. Please reload this page.
π Search Terms
keyof interface extends record number
π Version & Regression Information
β― Playground Link
Link
π» Code
π Actual behavior
IFKey
isnumber | string
π Expected behavior
IFKey
should bestring
The text was updated successfully, but these errors were encountered: