David Michael Gang David Michael Gang - 3 months ago 56
TypeScript Question

using documentMode with typescript

I check if the browser is ie by:

function isBrowserIE() {
return window.document.documentMode;
}


Typescript raises an error:


Error TS2339: Property 'documentMode' does not exist on type 'Document'.


This is due to the change made in typescript compiler at version 1.5 :


Properties documentMode, parentWindow, createEventObject are removed from type Document


How can i get rid from the error?

Answer

You can simply add it to the Document interface:

interface Document {
    documentMode?: any;
}

function isBrowserIE() {
    return window.document.documentMode;
}