Angel Angel
Angel Angel

Reputation: 21756

TypeScript readonly ( Error : Duplicate identifier 'readonly') ReferenceError: x is not defined

I was testing readonly following the basarat book. I have this error on IDE:

Duplicate identifier 'readonly'. (property) Foo.readonly: number

class Foo {

    readonly bar = 1;
    readonly baz: string;

    constructor() {
        this.baz = "hello";
    }
}

When I run the test, I get:

this.readonly = baz;
                ^
ReferenceError: baz is not defined

Something changed in typescript? I have to set something in the tsconfig.json to make use of this, I tried ES5 and ES6 and nothing changes

Upvotes: 1

Views: 975

Answers (1)

Fenton
Fenton

Reputation: 251262

The readonly keyword as described on this TypeScript GitHub issue is scheduled for the 2.0 milestone.

You will need to use version 2.0 or above for this feature to be available for instance and static members.

Upvotes: 2

Related Questions