gpt4 book ai didi

angularjs - 错误 TS2339 : Property 'endsWith' does not exist on type 'string'

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

我在下面的代码块中遇到了这个错误。

错误 TS2339:类型“string”上不存在属性“endsWith”

let myList = angular.element(elem).attr("href").split("/");
let last = _.last<string>(myList);
if (last.endsWith("something")) {
return last;
}

我还发现了这个链接,它显示有一个函数 endsWith(...)

http://definitelytyped.org/docs/typescript-services--typescriptServices/classes/typescript.stringutilities.html

我是否遗漏了一些 .d.ts 文件或什么?

最佳答案

在编译 typescript 代码时,请将目标指向 ES6。

tsc --target ES6 "filename"

关于angularjs - 错误 TS2339 : Property 'endsWith' does not exist on type 'string' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34431923/

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