tsconfig.json
{
"compilerOptions": {
"target": "ES2022",
"lib": [
"ES2022.Array"
]
}
}
app.ts
[1].at(0)
$tsc app.ts
app.ts:1:5 - error TS2550: Property 'at' does not exist on type 'number[]'.
Do you need to change your target library?
Try changing the 'lib' compiler option to 'es2022' or later.
1 [1].at(0)
~~
Found 1 error in app.ts:1
这是为何?
问题应该是 node 环境下 tsc 所需要的依赖缺失导致的,我在安装 @types/node 等依赖后问题得以解决。
package.json 如下: