Use modern JS in TS-Node on Arch-Linux

Acry, 19 July 2020

The Problem: One wants to use ES2020 or ESNEXT features with the global installed ts-node.
TS-Node defaults to ES3:

Current versions as time of writing

  • TS-Node 8.10.2
  • Typescript 3.9.7
  • NPM 6.14.6

Requirements

Expecting your npm is set up like in your shell’s runtime conditions:

PATH="$HOME/.node_modules/bin:$PATH"
export npm_config_prefix=~/.node_modules

Installation

Install TypeScript and TS-Node globally (user-wide in ~/.node_modules)

npm install -g ts-node
npm install -g typescript

Verify:

npm list -g --depth 0
├── ts-node@8.10.2
└── typescript@3.9.7

Setup TypeScript properly*

In your Terminal-Emulator:

cd ~
tsc --init
sed -i 's/"target": "ES3"/"target": "ES2020"/' tsconfig.json

*With properly I mean good enough to use Array.prototype.flat().
To set up TypeScript for your use-case see: https://www.typescriptlang.org/docs/handbook/compiler-options.html