Skip to content

Sometimes, keyof any is stringΒ #61203

Closed as not planned
Closed as not planned
@AFatNiBBa

Description

@AFatNiBBa

πŸ”Ž Search Terms

keyof any string

πŸ•— Version & Regression Information

Tested in the playground on "v3.3.3333" and "Nightly", it occurs in both versions

⏯ Playground Link

https://www.typescriptlang.org/play/?ts=5.8.0-dev.20250217#code/FAFwngDgpgBA8gIwFYwLwwN4wNoGsYCWAdjLlGAPYBmMAhkWALoBcMRArgLYJQBOMAX2AB6YTHEA9APzBQkWAGlyAZzSly1eMgDcIsZJnAAJlADGAG1q9YpikWUgYFZK0RJdzpNgDKYbhXMAOgIQPloQCl5GGFEYAAoAFQALAlUEa1pcZQBKIA

πŸ’» Code

type Obj = { [k in keyof any]: number }
//   ^? type Obj = { [x: string]: number; }

type Keys = keyof Obj;
//   ^? type Keys = string | number | symbol

declare const obj: Obj;
obj[Symbol.iterator] // (This breaks)

πŸ™ Actual behavior

The Obj type allows indexing only with strings

πŸ™‚ Expected behavior

The Obj type should allow indexing with every type of property key

Additional information about the issue

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Not a DefectThis behavior is one of several equally-correct options

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions