1

I have the following issue, "Cannot find name 'readonly'" when defining an interface with readonly properties. I have installed the following version of typescript: v 2.0.8 and I am using Visual Studio 2015.

Here is a sample:

TypeScript

interface Car {
    readonly engine: string;
    readonly model: string;
}

Any ideas will be appreciated.

7
  • Are you sure you're running the 2.0.8 version of typescript? Maybe your visual studio runs a different version? How did you install? Did you have a previous version installed before? Also, please add your tsconfig.json. Commented Nov 10, 2016 at 8:32
  • Yes I am sure about the version, I used the following cmd in npm console: "tsc -v". I am not sure about the "tsconfig.json", my project doesn't have this config, by adding this will it fix the problem? Is it like a prerequisite for a typescript project? Commented Nov 10, 2016 at 9:04
  • Visual studio might use a different version of typescript, so what you get when running tsc -v doesn't necessarily show the same version for what VS is running. Try this thread: stackoverflow.com/questions/23948348/… And this one: stackoverflow.com/questions/32385087/… Commented Nov 10, 2016 at 9:19
  • Okay I know what is the problem, I did install the newest version on the link and checked the directory "C:\Program Files\Microsoft SDKs\TypeScript\2.0" that it has the latest version, however in visual studio under help -> about visual studio it stil shows 1.7. I have no idea how to fix that. That would also explain why the intellisense is not picking it up and why I get the compilation error. Commented Nov 10, 2016 at 11:11
  • The 2nd link I posted in my last comment explains how to change it Commented Nov 10, 2016 at 11:17

1 Answer 1

1

You need to figure out where exactly do you get this error. Is it within Visual Studio (i.e. intellisense or during the project build). Or is it during the compilation with node (webpack or something) that uses the package.json e.g., where you have 2.0.8.

Since I have not seen 2.0.8 for Visual Studio, most likely you updated only the version for node. I bet you get this error from Visual Studio version of typescript. So you need to update it for Visual Studio.

Unfortunately you cannot do that directly from the extensions view, where it should really work. So you need to download it yourself: https://www.microsoft.com/en-us/download/details.aspx?id=48593

Sign up to request clarification or add additional context in comments.

5 Comments

Okay I know what is the problem, I did install the newest version on the link and checked the directory "C:\Program Files\Microsoft SDKs\TypeScript\2.0" that it has the latest version, however in visual studio under help -> about visual studio it stil shows 1.7. I have no idea how to fix that. That would also explain why the intellisense is not picking it up and why I get the compilation error.
I have 2.0.6.0 in there, so it seems the update did not work fully for you. Or maybe you need to restart VS/machine or something. I just installed the update and it did the trick... Perhaps you need to update VS 2015 itself first?
I think updating my visual studio would get me closer to an answer, because looking at my vs 2015 I only have update 1 installed on it, looking at Microsoft there is update 3 currently. Should I try that and then re-install typescript to see if that fixes the issue?
I think you should do that, yes. Update to Update 3 and install typescript once again. At least I have Update 3 for sure.
Cool thanks, will do that and if it works I will make this the accepted answer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.