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.

Erick Boshoff
  • 1,443
  • 2
  • 18
  • 30
  • 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`. – Nitzan Tomer Nov 10 '16 at 08: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? – Erick Boshoff Nov 10 '16 at 09: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: http://stackoverflow.com/questions/23948348/where-can-i-find-the-typescript-version-installed-in-visual-studio And this one: http://stackoverflow.com/questions/32385087/vs2015-change-typescript-version – Nitzan Tomer Nov 10 '16 at 09: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. – Erick Boshoff Nov 10 '16 at 11:11
  • The 2nd link I posted in my last comment explains how to change it – Nitzan Tomer Nov 10 '16 at 11:17
  • I followed the second link. So what I did there is unloaded my project, changed the version in the project file, reloaded the project, rebuild project, restarted visual studio and restarted my pc. I also went and added the correct environment variables but still no dice. – Erick Boshoff Nov 10 '16 at 12:13
  • I'm not a visual studio user, so my best advise to you is to move to webstorm or even VSCode. – Nitzan Tomer Nov 10 '16 at 12:19

1 Answers1

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

Ilya Chernomordik
  • 27,817
  • 27
  • 121
  • 207
  • 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. – Erick Boshoff Nov 10 '16 at 11:11
  • 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? – Ilya Chernomordik Nov 10 '16 at 11:33
  • 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? – Erick Boshoff Nov 10 '16 at 12:15
  • I think you should do that, yes. Update to `Update 3` and install typescript once again. At least I have Update 3 for sure. – Ilya Chernomordik Nov 10 '16 at 12:18
  • Cool thanks, will do that and if it works I will make this the accepted answer – Erick Boshoff Nov 10 '16 at 12:24