Skip to content

keyof object is number instead of string  #41669

Closed
@eek

Description

@eek

TypeScript Version: 4.1.2 (actually all versions 3.3.3 - 4.1.2)

Search Terms:
keyof declared object is not only string, keyof object type, keyof declared key, keyof

Code

type GenericObject = { [key: string]: any };
type GenericKeyType = keyof GenericObject;

Expected behavior:
GenericKeyType should be of type string

Actual behavior:
GenericKeyType is number | string

Playground Link:
https://www.typescriptlang.org/play?#code/C4TwDgpgBA4hB2EBOBLAxgeQEYCsJuCgF4oBvKAbQGsIQAuKAZ2FXgHMBdBgQ3hCgC+AbgBQI0JFgJk6ANK0AKuGgkaIAPYAzKYlSZc+YEKA

Related Issues:
Didn't find anything.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions