Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeScript 1.3 protected error

Recently installed new TS version into VS2013 and tried to use protected modifier. However TS validator shows me an error (and underlines protected word with a red line. I get an error like

Use of future reserver word. ; expected

looks like it's looking into old TS definitions. Checked the project file and there is 1.1 version of TypeScript. also running tsc -v produces 1.3.0.

Does somebody of you guys experience that? What i'm missing and what to do to fix that.

Thank you a lot for any help.enter image description here

export class SomeClass {
    protected metadata: Metadata;
    protected subItems: SomeClass[];
    constructor() {
    }
}
like image 401
Romko Avatar asked Nov 14 '14 11:11

Romko


People also ask

What do the error messages in typescript mean?

There is some terminology you’ll frequently see in error messages that is helpful to understand. TypeScript considers a type assignable to another type if one is an acceptable substitute for the other.

Can I use the protected keyword in typescript?

The protectedkeyword has landed. It is currently pre-release. If you are using a very new version of TypeScript you can now use the protectedkeyword... the answer below is for older versions of TypeScript. Enjoy. View the release notes for the protected keyword

Is it possible to access Super in typescript?

Old Answer TypeScript has only private- not protected and this only means private during compile-time checking. If you want to access super.propertyit has to be public.

How does the new protected modifier work in typescript?

protected works in TypeScript very similarly like it does from C#. The TypeScript release notes document it as such: The new protected modifier in classes works like it does in familiar languages like C++, C#, and Java. A protected member of a class is visible only inside subclasses of the class in which it is declared


2 Answers

thank you all guys. for your answers! the reason was (oh, what's the shame =) ) the ReSharper. It's validation was showing that error, suspending it i'm getting no errors now. Looks like JetBrains guys should update their definitions like Web Essentials did. As they aren't compatible with new TS version, 1.3. And no updates pending as for now.

Hope, it'll be useful for somebody else.

like image 137
Romko Avatar answered Sep 29 '22 10:09

Romko


The answer to your question then is ReSharper 9.0 EAP. It supports TypeScript 1.3 features: 'protected' modifier and tuples. You're welcome to try it. Though, yes, it's a pre-release version, so overall stability is not strictly guaranteed.

like image 37
Anton Avatar answered Sep 29 '22 08:09

Anton