UPDATE - I just discovered this article:
which suggests that my problem is likely this:
VisualStudio uses file lib.d.ts to learn interfaces of window objects, events, etc. This lib.d.ts is updated with each version of typescript you install. When some interface become obsolete, it is removed from lib.d.ts, and VisualStudio then marks usage of such an interface as invalid and refuses to build.
The article says this:
you can specify your own version of lib.d.ts to be used in your specific project by using
/// <reference path=”custom/path/to/lib.d.ts” />
in project-specific _reference.ts file.
How do I do that though? The compiler is complaining about the lib.d.ts that's in the solution that doesn't build, so which lib.d.ts do I have to specify, for the lib.d.ts to work with TypeScript 1.8?
The problem:
I have a Visual Studio 2015 solution that contains a number of projects. I've upgraded one of the projects (which has AngularJS) to a hybrid AngularJS/Angular app that uses TypeScript 2.6.2, and now one of the other projects (a purely AngularJS app) in the same solution fails to compile because of TypeScript errors.
The newly upgraded project is compiling fine (including the TypeScript), and it compiles via Visual Studio using the following tsconfig.json file:
{
"compilerOptions": {
"target": "es5",
"module": "system",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": [ "es2015", "dom" ],
"noImplicitAny": false,
"suppressImplicitAnyIndexErrors": true,
"noStrictGenericChecks": true
},
"include": [ "**/*.ts" ],
"exclude": [
"node_modules"
]
}
When I go into the project root folder via the command line in Windows, then type 'tsc -v', the output is 'Version 2.6.2', which I believe confirms the TypeScript version that Visual Studio is building against for this project.
The other project (that contains the 'pure' AngularJS code) only builds using Visual Studio (there isn't any tsc compilation using CLI). The project now shows *.ts errors in Visual Studio that weren't there before, including the following:
And I'm also seeing various *.d.ts errors:
The errors must be showing due to some kind of configuration change as there haven't been any code changes to the project, however I don't understand this because the project compiles through visual studio and doesn't use a tsconfig.json, and the project settings haven't changed. Here they are:
And the relevant .csproj settings:
<PropertyGroup>
<TypeScriptTarget>ES5</TypeScriptTarget>
<TypeScriptToolsVersion>1.8</TypeScriptToolsVersion>
... etc
When I was getting the 'hybrid' Angular/AngularJS project to work, at one stage I installed the 'TypeScript compiler v.2.6.2' globally in the Visual Studio solution using the VS nuget package manager, however I've since uninstalled it, and there has been nothing written to a packages.config file that's under source control. In any case the 'TypeScriptToolsVersion' in the project that's broken still points to v1.8 so I don't think that installing/uninstalling the nuget package is what's caused the problem. Here is what I now have in the C:\Program Files (x86)\Microsoft SDKs\TypeScript folder that Visual Studio usually uses when compiling TypeScript
I notice that the 'versions' file has 'LastKnownTypeScriptVersion' 2.6 as shown below, however when I edit that to 1.8 the project that has the errors now fails to load when I close and re-open Visual Studio
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<LastKnownTypeScriptVersion>2.6</LastKnownTypeScriptVersion>
</PropertyGroup>
</Project>
When I was configuring the hybrid app to work, I also did a global npm install of TypeScript 2.6.2, as well as an npm install of TypeScript 2.6.2 into the new 'hybrid app' project, however Visual Studio shouldn't be using those at all as those should be completely independent installs of TypeScript.
Is there anything obvious I could be missing here? I need some more ideas of what I can look at. Any comments or answers that give me some clue as to what's going on or what I could look at will be appreciated!