Skip to content

Object.keys has wrong return type from 2.1 #12870

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
davhdavh opened this issue Dec 13, 2016 · 1 comment
Closed

Object.keys has wrong return type from 2.1 #12870

davhdavh opened this issue Dec 13, 2016 · 1 comment
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@davhdavh
Copy link

TypeScript Version: 2.1.4

Code

let test = {a:1, b:1};
let a = Object.keys(test); //currently string[]

interface ObjectConstructor2 extends ObjectConstructor {
   keys<T>(o: T): (keyof T)[];
}
let correct = (<ObjectConstructor2>Object).keys(test);

Expected behavior:
keys actually returns keys

Actual behavior:
keys returns non-specific string array

@mhegazy
Copy link
Contributor

mhegazy commented Dec 13, 2016

This is intentional. Types in TS are open ended. So keysof will likely be less than all properties you would get at runtime.

@mhegazy mhegazy added the Working as Intended The behavior described is the intended behavior; this is not a bug label Dec 13, 2016
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug
Projects
None yet
Development

No branches or pull requests

3 participants