Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am trying to run this code but it is giving me following errors:

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";
    }
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
385 views
Welcome To Ask or Share your Answers For Others

1 Answer

The only thing which worked for me was to specify the Target on macOS and Windows. Please note the parameter -t is standing for Target.

tsc -t es5 script.ts

You can run the command on your terminal.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...