"Duplicate Identifier" errors in Visual Studio when trying to augment the Window interface


Basically i wanted to be able to do things like "new window.Image()", however "Image" is not defined on the "Window" interface, so the compiler throws an error.

So i tried to augment the interface:
interface Window {
    Image: new(width?: number, height?: number) => HTMLImageElement;
While this works on other interfaces, the Window interface seems kinda special, the line is being flagged as an error, saying "Duplicate Identifier 'Image'", in fact only function definitions aren't flagged, ie:
interface Window {
Interestingly the compiler is fine with it, ie it compiles without throwing any error, it's only Visual Studio flagging it as an error.
Closed Apr 12, 2013 at 11:48 PM by RyanCavanaugh
Fixed in 0.9 branch


RyanCavanaugh wrote Oct 9, 2012 at 10:37 PM

Thanks for reporting this issue - extending types that came from lib.d.ts does result in some odd behavior in Visual Studio. We're currently working on this bug.

mozts wrote Oct 10, 2012 at 3:36 PM

I am having the same issue however the example I have is that the WinJS.d.ts extends Element to add a property for winControl. this can be seen in the windows 8 sample app.

xps wrote Dec 6, 2012 at 11:47 PM

Can we raise the impact of this issue? I think it is a big bummer because it makes it impossible to extend types such as strings and arrays, preventing the porting of existing JavaScript code to TypeScript.

LukeH wrote Jan 19, 2013 at 12:56 AM

@xps - I've bumped up the impact of this issue, as we are aware this is blocking some libraries from being used currently.

mwisnicki wrote Mar 17, 2013 at 7:18 PM

It's not just Visual Studio - it happens in playground too. But curiously, when you refresh page the error goes away (valid errors are still highlighted) until you edit something.

jukka2 wrote Mar 28, 2013 at 4:22 PM

It seems to me that when the interface is inside a module, I'll get no errors.

jukka2 wrote Mar 28, 2013 at 9:59 PM

"It seems to me that when the interface is inside a module, I'll get no errors." Please forget my previous message.

I can make an extension to native Date object using an interface as a function, but not as an ordinal property without error messages in Visual Studio.

vmadman wrote Dec 19, 2013 at 4:28 AM

I've created a quick gist with my current workaround/solution for using Sugar.js's static extensions. I'm still pretty new to TypeScript, so I'm sure its not the best solution, but I did not see a workaround example in my own search so maybe this will help someone.

orreborre wrote Mar 10 at 12:37 PM

Having the same problem when I add jasmine nuget into a project in 1.0 RC...