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

Object.keys' returntype should be specified #49502

Closed
HomyeeKing opened this issue Jun 12, 2022 · 4 comments
Closed

Object.keys' returntype should be specified #49502

HomyeeKing opened this issue Jun 12, 2022 · 4 comments
Labels
Duplicate An existing issue was already created

Comments

@HomyeeKing
Copy link

HomyeeKing commented Jun 12, 2022

Bug Report

when you get keys of some object by Object.keys, then assign value to it, will get an error like
Element implicitly has an 'any' type because expression of type 'string' can't be used to index type

🔎 Search Terms

🕗 Version & Regression Information

  • This is a crash
  • This changed between versions ______ and _______
  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about _________
  • I was unable to test this on prior versions because _______

⏯ Playground Link

Playground link with relevant code

💻 Code

const obj = {a:1,b: 2}
for(const key of Object.keys(obj)){
  obj[key] = 3
}

🙁 Actual behavior

obj[key] will report error
image

🙂 Expected behavior

narrow Object.keys return type like

type Keys<T extends object> = (o:T) =>  UnionToTuple<keyof T>

maybe we coule implement UnionToTuple like thing

@jcalz
Copy link
Contributor

jcalz commented Jun 12, 2022

Duplicate of #45390 and a bunch of others. (Also see #13298 for why there is no union-to-tuple) Did you search for existing issues?

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Jun 13, 2022
@typescript-bot
Copy link
Collaborator

This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

@HomyeeKing
Copy link
Author

@jcalz yes I have searched and still no solution, just wanna get more attenion about this

@RyanCavanaugh
Copy link
Member

This is the intended behavior and we're not changing it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants