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 does not return strongly typed keys in es6 #15627

Closed
npenin opened this issue May 6, 2017 · 2 comments
Closed

Object.keys does not return strongly typed keys in es6 #15627

npenin opened this issue May 6, 2017 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@npenin
Copy link

npenin commented May 6, 2017

TypeScript Version: 2.3.2
Code

export function array<T>(array: T[], body: (element: T, i: number) => void)
{
    Array.prototype.forEach.call(array, body);
}

export function object<T>(o: T, body: <U extends keyof T>(element: T[U], i: U) => void)
{
    array(Object.keys(o), function (key, i)
    {
        body(o[key], key);
    });
}

Expected behavior:
No compile error

Actual behavior:
Compile error

severity: 'Error'
message: 'Argument of type 'string' is not assignable to parameter of type 'keyof T'.'
at: '10,22'
source: 'ts'
@hediet
Copy link
Member

hediet commented May 6, 2017

See #13254 and this comment. This is by design.

@DanielRosenwasser DanielRosenwasser added the Duplicate An existing issue was already created label May 6, 2017
@DanielRosenwasser
Copy link
Member

Thanks for finding that @hediet

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

No branches or pull requests

3 participants