【发布时间】:2016-05-01 11:36:21
【问题描述】:
我正在使用 babel-polyfill 和 typescript。
当我使用函数 string.includes() 时出现错误
错误 TS2339:“字符串”类型上不存在属性“包含”
堆栈溢出也有类似问题:error TS2339: Property 'endsWith' does not exist on type 'string'
答案是扩展自定义接口String
interface String {
endsWith(searchString: string, endPosition?: number): boolean;
};
我不太喜欢这个想法,因为这意味着我必须以这种方式修复每个 es6 polyfill 功能。
有没有办法告诉 typescript 他应该使用 es6 定义,但转译为 es5?
【问题讨论】:
标签: typescript babeljs