Property ‘entries’ does not exist on type ‘ObjectConstructor’

You’re quite correct that changing target is the wrong approach and changing lib is the correct approach, however you have specified the wrong version of the language. According to MDN, Object.entries was officially added in the ES2017 specification. “lib”: [“es2017”] is therefore what you must specify instead*. If you wish to add only the declarations … Read more

Can’t require() default export value in Babel 6.x

TL;DR You have to use const app = require(‘./app’).default; app(); Explanation Babel 5 used to have a compatibility hack for export default: if a module contained only one export, and it was a default export, it was assigned to module.exports. So, for example, your module app.js export default function () {} would be transpiled to … Read more

Javascript ES6 spread operator on undefined [duplicate]

This behavior is useful for doing something like optional spreading: function foo(options) { const bar = { baz: 1, …(options && options.bar) // options and bar can be undefined } } And it gets even better with optional chaining, which is in Stage 4 now (and already available in TypeScript 3.7+): function foo(options) { const … Read more

Difference between async/await and ES6 yield with generators

Well, it turns out that there is a very close relationship between async/await and generators. And I believe async/await will always be built on generators. If you look at the way Babel transpiles async/await: Babel takes this: this.it(‘is a test’, async function () { const foo = await 3; const bar = await new Promise(resolve … Read more

ES6 `export * from import`?

Yes, ES6 supports directly exporting imported modules: export { name1, name2, …, nameN } from …; export {FooAction, BarAction} from ‘./action_creators/index.js’ You can also re-export all exports of the imported module using the * syntax: export * from …; export * from ‘./action_creators/index.js’; More info on MDN.

When is the body of a Promise executed?

Immediately, yes, by specification. From the MDN: The executor function is executed immediately by the Promise implementation, passing resolve and reject functions (the executor is called before the Promise constructor even returns the created object) This is defined in the ECMAScript specification (of course, it’s harder to read…) here (Step 9 as of this edit, showing … Read more

How to get the first element of Set in ES6 ( EcmaScript 2015)

They don’t seem to expose the List to be accessible from the instanced Object. This is from the EcmaScript Draft: 23.2.4 Properties of Set Instances Set instances are ordinary objects that inherit properties from the Set prototype. Set instances also have a [[SetData]] internal slot. [[SetData]] is the list of values the Set is holding. … Read more

How to avoid imports with very long relative paths in Angular 2?

TypeScript 2.0+ In TypeScript 2.0 you can add a baseUrl property in tsconfig.json: { “compilerOptions”: { “baseUrl”: “.” // etc… }, // etc… } Then you can import everything as if you were in the base directory: import {XyService} from “services/validation/xy.service”; On top of this, you could add a paths property, which allows you to … Read more