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.values should not accept undefined or null #20550

Closed
aboyton opened this issue Dec 7, 2017 · 0 comments
Closed

Object.values should not accept undefined or null #20550

aboyton opened this issue Dec 7, 2017 · 0 comments
Labels
Bug A bug in TypeScript Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Fixed A PR has been merged for this issue

Comments

@aboyton
Copy link

aboyton commented Dec 7, 2017

TypeScript Version: 2.7.0-dev.201xxxxx
Reproduced locally with 2.5.3 but it seems to still be the case in master. https://github.com/Microsoft/TypeScript/blob/master/src/lib/es2017.object.d.ts

Code

const foo = Object.values(undefined);

Expected behaviour:
This should be a compile error, like Object.keys(undefined) is.

The type signature for Object.keys is

keys(o: {}): string[];

but for Object.values and Object.entities it is:

values<T>(o: { [s: string]: T }): T[];
values(o: any): any[];

entries<T>(o: { [s: string]: T }): [string, T][];
entries(o: any): [string, any][];

Ideally it would be nice to have specialisations for if o: string as well, but at minimum it would be nice to at least replace o: any with o: {} to catch the above error.

Actual behaviour:
This compiles correctly and gives a runtime error.

@mhegazy mhegazy added Bug A bug in TypeScript Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Fixed A PR has been merged for this issue labels Jan 8, 2018
@mhegazy mhegazy added this to the TypeScript 2.7 milestone Jan 8, 2018
@microsoft microsoft locked and limited conversation to collaborators Jul 3, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

2 participants