Questions tagged [ecmascript-2020]

ECMAScript 2020 (ES2020) is the 11th version of the ECMAScript language. It adds many important new features, including dynamic imports, globalThis, optional chaining, arbitrary precision BigInts and Promise.allSettled. Only use this tag where the question specifically relates to new features or technical changes provided in ECMAScript 2020.

ECMAScript 2020 (ES2020) is the 11th version of the language.

The following proposals have been merged:

Links

62 questions
29
votes
9 answers

Support optional chaining in vuejs

I have created vue and electron app using @vue/cli-service 4.2 in that I am facing a issue of optional chaining. I can't use ? for validating the condition like (@babel/plugin-proposal-optional-chaining) eg. a?.b?.c its means it check weather a…
Hardik Kothari
  • 1,686
  • 1
  • 15
  • 29
26
votes
2 answers

Named export 'Types' not found. The requested module 'mongoose' is a CommonJS module, which may not support all module.exports as named exports

I have an express server written in typescript with "module": "es2020" in its tsconfig. I've also developed another es2020 module for my graphql API, still in typescript, and this module uses mongoose with such named imports: import { Types } from…
0xChqrles
  • 433
  • 1
  • 5
  • 10
21
votes
2 answers

How is the nullish coalescing operator (??) different from the logical OR operator (||) in ECMAScript?

ES2020 introduced the nullish coalescing operator (??) which returns the right operand if the left operand is null or undefined. This functionality is similar to the logical OR operator (||). For example, the below expressions return the same…
francis
  • 3,852
  • 1
  • 28
  • 30
10
votes
3 answers

How should I use ES2020 in Angular?

Here is my tsconfig.json file: { "compileOnSave": false, "compilerOptions": { "baseUrl": "./", "outDir": "./dist/out-tsc", "sourceMap": true, "declaration": false, "module": "es2015", …
Swanand Taware
  • 723
  • 2
  • 7
  • 32
6
votes
4 answers

How to use es2020 features in vue 2.6 project?

I have a Vue 2.6 project and I want to use the es2020 characteristics like optional chaining in my project but I can't get it to work in my project. I'm getting the following error. > vue-cli-service serve INFO Starting development server... 98%…
Loop
  • 73
  • 1
  • 7
6
votes
2 answers

How to add es2020 features to existing react app?

I want to use the new features of es2020 in my react app. Tried to install npm install --save-dev babel-preset-es2020 and added .babelrc file with { "presets": ["es2020"] } However it still doesn't work. How to set up the new features of es2020…
Kaki6876
  • 77
  • 1
  • 6
6
votes
1 answer

Module Parse Failed With Optional-Chaining in Angular 10 and ES2020

Just updated to Angular 10 from 9.0 Every use of Optional Chaining (https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#optional-chaining) in my code now results in its own instance of the following error ERROR in…
JimbobTheSailor
  • 1,441
  • 1
  • 12
  • 21
5
votes
0 answers

Can the ES2020 nullish coalescing operator (??) be used to check undeclared variables?

From MDN: The nullish coalescing operator (??) is a logical operator that returns its right-hand side operand when its left-hand side operand is null or undefined, and otherwise returns its left-hand side operand. However, the following statement…
aalaap
  • 4,145
  • 5
  • 52
  • 59
5
votes
1 answer

Why does the new "matchAll" in Javascript return an iterator (vs. an array)?

ES2020 contains a new String.prototype.matchAll method, which returns an iterator. I'm sure I'm missing something dumb/obvious, but I don't see why it doesn't just return an array instead. Can someone please explain the logic there? EDIT: Just to…
machineghost
  • 33,529
  • 30
  • 159
  • 234
4
votes
1 answer

How to copy values of only a subset of object properties to another existing object in TypeScript

Lets say I have an existing object obj1 = {a: 'A', b: 'B', c: 'C', d: 'D'} I have another object something like obj2 = {b: 'B2', c: 'C2', d: 'D2', e: 'E2'} Now I want to selectively copy the values of only a few properties from obj2 to obj1, for…
Arghya C
  • 9,805
  • 2
  • 47
  • 66
4
votes
2 answers

Why javaScript's Optional Chaining Syntax does not work with Nullish Coalescing Operator when there is no method's return value?

I"m trying the new JavaScript Optional Chaining syntax and it seems that it has an issue with methods which has no return value. For example: I have a restaurant object with order method in it: const restaurant = { order(i, k) { console.log(`I…
Irfan
  • 4,882
  • 12
  • 52
  • 62
4
votes
1 answer

Optional chaining logic

I'm not sure I get the logic behind the js implementation of optional chaining. const a = {b:1} 1 > console.log(a?.c) => undefined 2 > console.log(a?.c?.d) => undefined 3 > console.log(a?.c.d) => Uncaught TypeError: Cannot read property 'd'…
alfredopacino
  • 2,979
  • 9
  • 42
  • 68
3
votes
1 answer

Are private fields of subclasses of built-in classes not accesible inside overriden methods?

I have the following class that extends the built in data type Set. It adds a little bit of extra functionality by checking that every element that wants to be added to the set conforms to the type specified as the first parameter of the…
Ariel
  • 155
  • 1
  • 2
  • 11
3
votes
0 answers

Is NestJS compatible with es2020 typescript?

when building a skeleton NestJS app, it sets es2017 in tsconfig. When trying to change it to es2020, it seems to work but hard to say without testing everything. I was unable to find any insights online. Are there any known issues with es2020…
Sagi Mann
  • 2,967
  • 6
  • 39
  • 72
3
votes
1 answer

How to run Typescript ES6+ server side via .net core and nodejs using Jering.Javascript.NodeJS

I want to run some TypeScript Code written in ES2020 on Server Side. Currently i have running a ASP.NET Core Application so the idea was to run js via Jering.Javascript.NodeJS and nodejs. So started with a basic example. var test = await…
Peter Paan
  • 51
  • 6
1
2 3 4 5