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.entries implements code error! #40243

Closed
tangjfn opened this issue Aug 25, 2020 · 4 comments · Fixed by #40268
Closed

Object.entries implements code error! #40243

tangjfn opened this issue Aug 25, 2020 · 4 comments · Fixed by #40268
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue

Comments

@tangjfn
Copy link

tangjfn commented Aug 25, 2020

TypeScript Version: 4.0.2

Search Terms:

Code

typescript.js at line 1479

Expected behavior:

var _entries = Object.entries ? Object.entries : function (obj) {
var keys = getOwnKeys(obj);
var result = Array(keys.length);
for (var _i = 0, keys_1 = keys; _i < keys_1.length; _i++) {
var key = keys_1[_i];
result[i] = [key, obj[key]];
}
return result;
};

Actual behavior:

var _entries = Object.entries ? Object.entries : function (obj) {
var keys = getOwnKeys(obj);
var result = Array(keys.length);
for (var _i = 0, keys_1 = keys; _i < keys_1.length; _i++) {
var key = keys_1[_i];
result.push([key, obj[key]]);
}
return result;
};

Playground Link:

Related Issues:

@RyanCavanaugh RyanCavanaugh added the Working as Intended The behavior described is the intended behavior; this is not a bug label Aug 25, 2020
@RyanCavanaugh
Copy link
Member

The proposed diff would fail to run.

Please be more explicit about why you think this is wrong

@tangjfn
Copy link
Author

tangjfn commented Aug 26, 2020

var result = Array(keys.length);
...
result.push([key, obj[key]]); // here is wrong

result[0 .. keys.length] is undefined

entries push after result[keys.length]

@tangjfn
Copy link
Author

tangjfn commented Aug 26, 2020

it is run normally because most javascript has Object.entries function.

@RyanCavanaugh RyanCavanaugh removed the Working as Intended The behavior described is the intended behavior; this is not a bug label Aug 26, 2020
@RyanCavanaugh
Copy link
Member

I misread "Expected" and "Actual" - yes, this is indeed broken.

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Aug 26, 2020
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 4.0.3 milestone Aug 26, 2020
RyanCavanaugh added a commit to RyanCavanaugh/TypeScript that referenced this issue Aug 26, 2020
@typescript-bot typescript-bot added the Fix Available A PR has been opened for this issue label Aug 26, 2020
RyanCavanaugh added a commit that referenced this issue Aug 28, 2020
* Use a correct Object.entries polyfill

Fixes #40243

* Update src/compiler/core.ts

Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com>

* Added parentheses, DANIEL.

Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants