Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using documentMode with typescript

Tags:

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?

like image 887
David Michael Gang Avatar asked Aug 16 '16 11:08

David Michael Gang


2 Answers

I've used bracket notation to get rid of the error:
document['documentMode']

like image 181
user5480949 Avatar answered Sep 28 '22 05:09

user5480949


You can simply add it to the Document interface:

interface Document {
    documentMode?: any;
}

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

Edit

If you are using modules then you need to use global augmentation:

declare global {
    interface Document {
        documentMode?: any;
    }
}
like image 29
Nitzan Tomer Avatar answered Sep 28 '22 05:09

Nitzan Tomer