TypeScript 1.3 protected error

A new version of TS was recently installed in VS2013 and tried to use the protected modifier. However, the TS validator shows me an error (and underlines the word protected red line). I get an error like

Using the future dictionary for backup .; Expected,

It looks like he is studying old definitions of TS. Check the project file and TypeScript version 1.1. also works tsc -v produces 1.3.0 .

Do any of you guys experience this? What I am missing and what to do to fix it.

Thanks so much for any help. enter image description here

 export class SomeClass { protected metadata: Metadata; protected subItems: SomeClass[]; constructor() { } } 
+6
source share
5 answers

Thanks to everyone guys. for your answers! the reason was (oh, what a shame =)) ReSharper . He confirmed that the error, pausing it, now I get no errors. It seems like the JetBrains guys should update their definitions, as Web Essentials did. Since they are not compatible with the new TS version 1.3. And while updates are not expected.

Hope this will be helpful to someone else.

+7
source

Then the answer to your question is ReSharper 9.0 EAP . It supports TypeScript 1.3 features: "protected" modifier and tuples. You can try. Although, yes, this is a preliminary version, so overall stability is not guaranteed strictly.

+3
source

Are you building from Visual Studio or from the command line? That when you install different versions of the SDK, as well as potentially the NPM package worldwide (if you ever installed it), it can become quite confusing as to which version will be upgraded. For example, if I run 'where tsc' from the command line, I get the following images (and this does not have a 1.1 SDK in the path, although I'm in the bin folder to test the last bits)

 S:\src\TypeScript\bin>where tsc S:\src\TypeScript\bin\tsc S:\src\TypeScript\bin\tsc.js C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.0\tsc.exe C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.0\tsc.js C:\Users\billti\AppData\Roaming\npm\tsc C:\Users\billti\AppData\Roaming\npm\tsc.cmd 

Can you check the "where tsc" location and order the PATH command "tsc"?

However, if you are building a VS project, it should find the latest SDK through the build target. Does this also happen with the new TypeScript project (where should I refer to the latest version and goals file)?

Otherwise, and I hate to say this ... done ... did you try to restart? :-) Sometimes updates for PATH, etc. After installation, they don’t get until the processes restart, and things like MSBuild may be delayed waiting for the next build as a perforated optimization, and not exit after the build is completed (and therefore cannot immediately receive changes in the environment )

+2
source

That didn't work either. I tried installing VS2013 Update 4, and after that I did Type Type 1.3 setup again and performed the repair.

In addition, you must make sure that there is no <TypeScriptToolsVersion>1.0</TypeScriptToolsVersion> in your csproject. Set it to 1.1 (not 1.3) or completely remove it (then it will use the latter). Hope this helps!

+1
source

You can determine if the problem is with Visual Studio by specifying the wrong TypeScript version by following these steps.

Put this sample code in C:\Temp\app.ts

 interface Metadata { something: string; } export class SomeClass { protected metadata: Metadata; protected subItems: SomeClass[]; constructor() { } } export class OtherClass extends SomeClass { constructor() { super(); this.metadata = null; } } var x = new SomeClass(); // Not allowed // x.metadata = null; 

Run the command:

 C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.1>tsc --module amd c:\Temp\app.ts 

Making sure you specify folder 1.1 in the TypeScript SDK folder.

The output should be:

 C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.1> 

i.e. nothing except that you have the app.js. file

You can also re-run the test after uncommenting the line x.metadata = null; - at this moment you should get an error:

c: /Temp/app.ts (22,1): error TS2445: property metadata is protected and accessible only in the SomeClass class and its subclasses.

Next steps...

If the above fails , please provide details of the problem.

The only real answer that we could give, although it will delete it, and verify that folder 1.1 is gone before reinstalling it by extracting the installer from the Microsoft website (maybe you have a bad installation or some problem during installation? ) You can also check that you are in Visual Studio Update 4, since I am testing it on Update 4.

If the above worked as expected , your Visual Studio is not pointing to the correct version.

This may be due to the project file, as Dick van den Brink correctly mentioned. Make sure you have <TypeScriptToolsVersion>1.1</TypeScriptToolsVersion> and that this is the only element with this name.

It may also not be available for any Visual Studio extensions that may interact with your TypeScript (for example, if you had a really old version of Web Essentials - in this case, update it - if it is a different extension, try disabling it).

+1
source

Source: https://habr.com/ru/post/978188/


All Articles