Skip to content

keyof behaves differently with index signatures created using Record #63216

@juhort

Description

@juhort

Acknowledgement

  • I acknowledge that issues using this template may be closed without further explanation at the maintainer's discretion.

Comment

type T1 = { [x: string]: unknown };
//   ^? type T1 = { [x: string]: unknown; }
type K1 = keyof T1;
//   ^? type K1 = string | number


type T2 = Record<string, unknown>;
//   ^? type T2 = { [x: string]: unknown; }
type K2 = keyof T2;
//   ^? type K2 = string

Expected: K2 should have also been string | number because:

  1. We can access number from T2:

    type AccessT2 = T2[number]; // ✅ Allowed
    //   ^? type AccessT2 = unknown
  2. T2 is the same as T1 so their keyof behavior should also be same.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions