-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
lib.d.ts Make Object.keys generic #19448
Comments
Please see #15627 |
This comment But I'm not convinced. We either have strong typing or not. if someone is depending on runtime data without statically declaring them it is their problem and can case the types to a wide type /cc @ahejlsberg Closing as it is by design |
At the moment, TypeScript does not differentiate between own keys and enumerable keys, both which are not covered by For example, it breaksdown badly here: const foo = Object.create({ foo: 'string' });
Object.defineProperty(foo, 'bar', {
value: 1
});
console.log(Object.keys(foo)); // []
console.log(foo.foo); // 'string'
console.log(foo.bar); // 1 Sounds like a bad 👣 🔫 to me... |
TypeScript Version: 2.5
Currently
Object.keys
type iskeys<T>(o: {}): string[];
but instead it can bekeys<T = {}>(o: T): keyof T;
so return type is a union of keys.Any reason this hasn't been done before? I can make a PR if this is an acceptable change
The text was updated successfully, but these errors were encountered: