访问者仅在定位ECMAScript 5及更高版本时可用 [英] Accessors are only available when targeting ECMAScript 5 and higher
本文介绍了访问者仅在定位ECMAScript 5及更高版本时可用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试运行此代码,但它给了我以下错误:
I am trying to run this code but it is giving me following errors:
Animal.ts(10,13):错误TS1056:只有当
针对ECMAScript 5及更高版本时才能使用访问者。 Animal.ts(14,13):错误TS1056:
访问者仅在定位ECMAScript 5及更高版本时可用。
Animal.ts(10,13): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. Animal.ts(14,13): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
interface IAnimal{
name : string;
sayName():string;
}
class AnimalImpm implements IAnimal{
private _name : string = '[Animal]';
get name():string{
return this._name;
}
set name(name:string){
this._name = name;
}
constructor(name:string){
this.name = name;
}
sayName():string {
console.log(`My name is ${this.name}`);
return "Hello";
}
}
推荐答案
唯一对我有用的是在macOS和Windows上指定目标
。
The only thing which works for me was to specify the Target
on macOS and Windows.
tsc --target es5 script.ts
您可以在终端上运行命令。
You can run the command on your terminal.
这篇关于访问者仅在定位ECMAScript 5及更高版本时可用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文