Typescript Error: TS2304, TS2411, TS2320 with AngularJs.DefinitelyTyped in blank solution

32 minutes to read read

Recently started with TypeScript with Visual Studio for the AngularJs and landed into a deep problem. The problem was that i was on a blank solution/project with no changes, and still there was a build error. The transition was assumed to be ok, but it didn’t turned out. So here  are the steps I did:

  1. Create a new MVC project in Visual Studio 2015. Added references for Angular using the PM Console.
    Command: install-package angularjs
  2. At this point solution should compile well.
  3. Install the DefinitrlyTyped typings for TypeScript for angularjs from PM Console.
    Command: install-package angularjs.typescript.definitelytyped
  4. Once installed, the solution should still compile ok, because as of now there is no TS file in the solution that should be compiled.
  5. Add a .ts file to the project and add a simple function. This would initiate the TSC to come in picture and compile ts bindings.
  6. Now building the solution gives a whole lot of compiler errors and compiler fails. The main errors are TS2304, TS2411, TS2320, . I get around 482 of such errors. The error loig from visual studio is attached below:
  7. This is off course bad and was a blocker for me, that hold me for a while. I did try well on google and stackoverflow, but all seemed to be out of context and was not much helpful, untill i pulled up my weapons to search the miscreant 🙂

The Problem and solution……

The problem with the solution is very simple. When you pulled the DefeinitelyTyped typings for angular, it automatically pulled the jquery Typings. The root cause is that the version of the typings for jquery imported was 0.0.1. I think this is because the dependency mentioned in the Angularjs.TypeScript.DefinitelyTyped package is wrongly mentioned.

To Resolve the solution just put the following command in PM Console to get the latest version of typescripts for jquery.
Command: Update-Package jquery.TypeScript.DefinitelyTyped

This shall update the typings (currently 3.0.3). Now build the solution. You will notice that most of the errors are gone except for a few. The error that is left is:

TS2304: Cannot find name ‘Promise’.

 

The reason for this is apparently that the default build version of ECMA script is version 5, which does not contain the definition for the ‘Promise’. The quickest solution is update the compile version of ECMAScriptVersion to 6. To do this, goto project settings –> TypeScript Build–> ECMA Version ==> ECMASCript 6.

Now Rebuild the solution and it should build successfully.

1 comment

Leave a Reply to Pilot Pirx Cancel reply

Your email address will not be published. Required fields are marked *