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

Create Compatibility with Object.fromEntries() with ES5 #32803

Closed
4 of 5 tasks
waynevanson opened this issue Aug 11, 2019 · 3 comments
Closed
4 of 5 tasks

Create Compatibility with Object.fromEntries() with ES5 #32803

waynevanson opened this issue Aug 11, 2019 · 3 comments

Comments

@waynevanson
Copy link

waynevanson commented Aug 11, 2019

Search Terms

Object.fromEntries()

Suggestion

I'd like to see Object.fromEntries() available to use as a function when compiling to the browser compatible ES5.

Use Cases

Using Object.fromEntries() when targeting ES5 alongside the friendly Object.entries()

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/fromEntries

Examples

Here is the polyfill from TC39 https://github.com/tc39/proposal-object-from-entries/blob/master/polyfill.js

  
function ObjectFromEntries(iter) {
  const obj = {};

  for (const pair of iter) {
    if (Object(pair) !== pair) {
      throw new TypeError('iterable for fromEntries should yield objects');
    }

    // Consistency with Map: contract is that entry has "0" and "1" keys, not
    // that it is an array or iterable.

    const { '0': key, '1': val } = pair;

    Object.defineProperty(obj, key, {
      configurable: true,
      enumerable: true,
      writable: true,
      value: val,
    });
  }

  return obj;
}

Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.

My Questions

  • Is this feature left out intentionally?
  • A guide/where to look when contributing to adding a feature like this?
@jcalz
Copy link
Contributor

jcalz commented Aug 11, 2019

  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)

A polyfill for a function is a runtime feature. See #26087

@waynevanson
Copy link
Author

Okay, so it is left out on purpose.

Thank you for your response :)

@HrshPtl
Copy link

HrshPtl commented Sep 23, 2019

Object.fromEntries() is not support in Microsoft Edge. so there are any replacement of this ?

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

No branches or pull requests

3 participants