I have a Node script with Typescript, where i want to extract an object (from a file), that occasionally is null. Therefore i want to use operational chaining (or some other operator) that allows me to have a fallback to null
if the object does not exists
const {
type: jackpotType,
contribution: jackpotContribution,
contributionEnable: jackpotContributionEnable,
}: {
type: string | null;
contribution: number | null;
contributionEnable: boolean | null;
} = entry.data?.jackpot;
when i compile i get this error:
SyntaxError: Unexpected token .
I have checked my node version (recently upgraded), and it should be compatible.
$ node --version // v15.8.0
and in my tsconfig.json
I have the following settings
{
"compilerOptions": {
/* Visit https://aka.ms/tsconfig.json to read more about this file */
/* Basic Options */
// "incremental": true, /* Enable incremental compilation */
"target": "ESNEXT" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */,
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */,
// "lib": [],
....