0

We have been using TypeScript for a while and specifically this line to overcome IE's issue with the Console.

if (typeof console == "undefined" || typeof console.log == "undefined") var console = <any>{ log: function () { } };

However I upgraded my Web Essentials version recently to the latest, 1.85, and now I am getting the error on this line of code that has not changed.

Subsequent variable declarations must have the same type.  Variable 'console' must be of type 'Console', but here has type 'any'.

I did try this page TypeScript: console is undefined in IE but I get errors trying to redefine window.console on some of the solutions.

Anyone else encountered this and what did they do about it?

Community
  • 1
  • 1
Kurt LP
  • 98
  • 1
  • 5

1 Answers1

0

That error is correct. Your code should be :

if (typeof console == "undefined" || typeof console.log == "undefined") 
    console = <any>{ log: function () { } };

since var console is already defined in lib.d.ts

basarat
  • 261,912
  • 58
  • 460
  • 511
  • 1
    It ends up that Typescript has become aware of the Console object, so the solution we used was to do the same line but with this minor change: `if (typeof console == "undefined" || typeof console.log == "undefined") var console = { log: function () { } };` replacing **any** with **Console** – Kurt LP Feb 25 '14 at 08:20