【发布时间】:2021-05-16 22:47:56
【问题描述】:
我有一个带有 Typescript 的 Node 脚本,我想(从文件中)提取一个对象,该对象偶尔为空。因此,我想使用操作链接(或其他一些运算符),如果对象不存在,我可以回退到 null
const {
type: jackpotType,
contribution: jackpotContribution,
contributionEnable: jackpotContributionEnable,
}: {
type: string | null;
contribution: number | null;
contributionEnable: boolean | null;
} = entry.data?.jackpot;
当我编译我得到这个错误:
SyntaxError: Unexpected token .
我已经检查了我的节点版本(最近升级),它应该是兼容的。
$ node --version // v15.8.0
在我的tsconfig.json 中,我有以下设置
{
"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": [],
....
【问题讨论】:
标签: node.js typescript