看起来可选链已经到位了has landed。这是一个例子
我无法弄清楚如何让TS正确编译它。在我的项目中没有语法错误,但是这个:
let imageFileId = (await db.query(sql`select id from image_files where sha256=${sha256}`))[0]?.id;
输出结果为:
let imageFileId = (await db.query(mysql3_1.sql `select id from image_files where sha256=${sha256}`))[0]?.id;
在 Node 中,只有当我们获得原生支持时才能运行。
这是我的 tsconfig:
{
"compilerOptions": {
"strict": true,
"importHelpers": false,
"inlineSources": true,
"noEmitOnError": true,
"pretty": true,
"module": "commonjs",
"noImplicitAny": true,
"suppressImplicitAnyIndexErrors": false,
"removeComments": false,
"preserveConstEnums": false,
"sourceMap": true,
"lib": ["es2018"],
"skipLibCheck": false,
"outDir": "dist",
"target": "esnext",
"declaration": false,
"resolveJsonModule": true,
"esModuleInterop": false,
"moduleResolution": "node",
"allowSyntheticDefaultImports": true,
"baseUrl": ".",
"paths": {
"*": ["src/*"]
},
"noEmit": false
},
"files": [
"src/index"
],
"include": [
"src/**/*.d.ts"
]
}
我需要启用其他选项才能编译?.
运算符吗?
请注意,我没有使用Babel,并且不想引入它。
es2019
,以便“polyfill”可选链操作符。 - icl7126ES2019
。 - Nikita Cherednichenkotarget: ES2019
对于 TS 3.9.5 仍然有效。 - I'll Eat My Hat