Skip to content

Recommended tsconfig.json target option for Node 14 is ES2020 which is not fully supported by Node 14. #46325

Closed
@ansavchenco

Description

@ansavchenco

Bug Report

🔎 Search Terms

node 14, tsconfig.json, es2020, recommended

Problem

According to the Node Target Mapping wiki page the recommended tsconfig.json for Node 14 is:

{
  "compilerOptions": {
    "lib": ["ES2020"],
    "module": "commonjs",
    "target": "ES2020"
  }
}

However, if we look at the node.green ES2020 feature support table we will see that Node 14 does not support one feature of ES2020 which is "spread parameters after optional chaining".

⏯ Playground Link

Playground link with relevant code

💻 Code

input.ts:

type Fn = ((...args: unknown[]) => void) | null;
type O = { method?: (...args: unknown[]) => void };
type N = { method: (...args: unknown[]) => void } | null;

var fn: Fn = null;
var n: N = null;
var o: O = {};

function func(fn: Fn, n: N, o: O) {
  return (
    fn?.(...[], 1) === void undefined &&
    fn?.(...[], ...[]) === void undefined &&
    o.method?.(...[], 1) === void undefined &&
    n?.method(...[], 1) === void undefined
  );
}

console.log(func(fn, n, o));

Output JavaScript:

"use strict";
var fn = null;
var n = null;
var o = {};
function func(fn, n, o) {
    return (fn?.(...[], 1) === void undefined &&
        fn?.(...[], ...[]) === void undefined &&
        o.method?.(...[], 1) === void undefined &&
        n?.method(...[], 1) === void undefined);
}
console.log(func(fn, n, o));

🙁 Actual behavior

/Users/antonsavcenko/Development/misc/typescript/src/index.js:5
    return (fn?.(...[], 1) === void undefined &&
    ^

TypeError: Function.prototype.apply was called on null, which is a object and not a function
    at func (/Users/antonsavcenko/Development/misc/typescript/src/index.js:5:5)
    at Object.<anonymous> (/Users/antonsavcenko/Development/misc/typescript/src/index.js:10:13)
    at Module._compile (internal/modules/cjs/loader.js:1072:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
    at Module.load (internal/modules/cjs/loader.js:937:32)
    at Function.Module._load (internal/modules/cjs/loader.js:778:12)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12)
    at internal/main/run_main_module.js:17:47

🙂 Expected behavior

true

Metadata

Metadata

Assignees

Labels

DocsThe issue relates to how you learn TypeScript

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions