Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sometimes, keyof any is string #61203

Open
AFatNiBBa opened this issue Feb 17, 2025 · 1 comment Β· May be fixed by #61224
Open

Sometimes, keyof any is string #61203

AFatNiBBa opened this issue Feb 17, 2025 · 1 comment Β· May be fixed by #61224

Comments

@AFatNiBBa
Copy link

πŸ”Ž 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

@mkantor
Copy link
Contributor

mkantor commented Feb 21, 2025

I came across a relevant comment that may be of interest to anyone looking at this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants