ipi*_*nak 9 angularjs typescript ecmascript-6 lodash
我在下面的代码块中得到此错误.
error TS2339: Property 'endsWith' does not exist on type 'string'
let myList = angular.element(elem).attr("href").split("/");
let last = _.last<string>(myList);
if (last.endsWith("something")) {
return last;
}
Run Code Online (Sandbox Code Playgroud)
我还发现这个链接显示有一个功能endsWith(...).
我想念一些.d.ts文件或者什么?
Mar*_*cka 14
endsWith是ES6函数,因此您需要ES6在TypeScript编译器设置中进行定位,或者可以为其添加接口:
interface String {
endsWith(searchString: string, endPosition?: number): boolean;
};
Run Code Online (Sandbox Code Playgroud)
[ 游乐场 ]
wan*_*onk 14
在编译打字稿代码时,请将目标指向ES6.
tsc --target ES6 "filename"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10775 次 |
| 最近记录: |