gpt4 book ai didi

TypeScript:无法识别 ES2015 字符串属性 'repeat'

转载 作者:搜寻专家 更新时间:2023-10-30 20:43:43 25 4
gpt4 key购买 nike

条件:我正在使用 Win10、TypeScript 1.8 和 Visual Studio Code 1.0.0。我有这样的代码

///<reference path = "./typings/lib.es6.d.ts" />

后来

let z = "0".repeat(4 - str.length)

这是 let z 行。

VS Code 在“repeat”下加上红色下划线并报告

[ts] Property 'repeat' does not exist on type 'string'.

我在命令行编译

tsc <filename>.ts

指向 let z 行中 repeat 的开始,编译器报告

error TS2339: Property 'repeat' does not exist on type 'string'.

开始有所不同,TypeScript,但它是在 ES2015 (ES6) 中添加的。

问题:如何获得干净的编译?

编辑:缩短。

最佳答案

在我的例子中,我只更改了 tsconfig.json 文件中的这一行:

之前:

"compilerOptions": {
"target": "es5"
}

之后:

"compilerOptions": {
"target": "es6"
}

关于TypeScript:无法识别 ES2015 字符串属性 'repeat',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37009997/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com