Skip to content

Object.keys incorrect return type #34498

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

Closed
Connormiha opened this issue Oct 15, 2019 · 2 comments
Closed

Object.keys incorrect return type #34498

Connormiha opened this issue Oct 15, 2019 · 2 comments
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@Connormiha
Copy link

Connormiha commented Oct 15, 2019

TypeScript Version: 3.7.x-dev.201xxxxx

Search Terms:

Code

const a = { a: 'foo' };

Object.keys(a).forEach((key) => {
    console.log(a[key]);
});

Expected behavior:
No error

Actual behavior:

Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{ a: string; }'.
  No index signature with a parameter of type 'string' was found on type '{ a: string; }'.

Playground Link:
https://www.typescriptlang.org/play/?ssl=9&ssc=4&pln=6&pc=1#code/MYewdgzgLgBAhjAvDA3vAXDA5AMxCLGAXwG4BYAKEoHkAjAKwFNgoA6Aa0YE8IAKOAJSs8AJwCicYAAtevTlwFIAfKkox1MUJBAAbRqx0gA5vwDa8gLoDyFItcpA

Related Issues:

@dragomirtitian
Copy link
Contributor

There are good reasons for the current types.

Read here for the explanation : So answer

@RyanCavanaugh
Copy link
Member

Search Terms:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug
Projects
None yet
3 participants