100+ errors in jQuery.d.ts since getting latest via nuget in MVC application

Gone Coding picture Gone Coding · Feb 17, 2015 · Viewed 11.3k times · Source

Ever since I updated to the latest jQuery.d.ts definition file, using the Visual Studio NuGet package manager, I now get 100s of errors within the jQuery.d.ts file.

The pattern to all the errors is vertical lines like this:

index(selector: string|JQuery|Element): number;

which I assume indicates optional types. The errors mostly look like:

\Scripts\typings\jquery\jquery.d.ts(2797,34): error TS1005: Build: ',' expected.

The default Build Action was TypeScriptCompile, but changing that to none has no effect.

I am running Visual studio 2013 Professional release 4, so assumed I would have the latest TypeScript version, but this looks like a versioning issue.

Any ideas on how to resolve the problem.

Answer

Andrzej Turski picture Andrzej Turski · May 11, 2015

When you have an existing VS 2013 project that used an earlier version of TypeScript and you want to upgrade to the latest nuGet packages of jquery.d.ts or knockout.d.ts, installation of the latest TypeScript compiler is not enough.

After installing the latest TypeScript from
https://visualstudiogallery.msdn.microsoft.com/2d42d8dc-e085-45eb-a30b-3f7d50d55304
you need to edit project definition files to turn on version 1.4 features. This is done by changing the line
<TypeScriptToolsVersion>1.0</TypeScriptToolsVersion>
to
<TypeScriptToolsVersion>1.4</TypeScriptToolsVersion>

Also, please be aware that your TS code may require some changes too. Specifically, FormData constructor does not take HTML element as an argument anymore. The simplest workaround is to change code like this one:
var formData = new FormData(<HTMLFormElement>$("#form")[0]);
to
var formEl = <HTMLFormElement>$("#form")[0]; var formData = new window['FormData'](formEl);