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

Add Shim for Object.entries #63

Closed
wants to merge 2 commits into from

Conversation

jherdman
Copy link

@jherdman jherdman commented Jan 15, 2020

Resolves #62

Since Ember supports IE11 we'll need to shim Object.entries.
addon/index.ts Outdated

while (i--) {
const key = keys[i];
const newEntry = [key, object[key]];
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm really new to Typescript, and I just can't figure this line out. The following error is noted:

Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{}'.  No index signature with a parameter of type 'string' was found on type '{}'.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you change the type definition of the object argument to Record<string, any> it should work.

You could also use {[key: string]: any} as both tell TS to allow access to the object keys by using an index.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the while loop a performance optimization?
Otherwise you could neatly solve this with a .map:

export const objectEntries: typeof Object.entries = <T>(object: {
  [key: string]: T;
}) => Object.keys(object).map(key => [key, object[key]] as [string, T]);

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ended up going with @buschtoens solution, seemed tighter to me.

@jherdman jherdman marked this pull request as ready for review January 15, 2020 15:50
Uses Object.keys, which is available in IE11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Broken with IE11
3 participants