Reputation: 7299
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?
Upvotes: 18
Views: 9415
Reputation: 610
I like to use @ts-ignore
since I know that document.documentMode
will never cause a problem when it's compiled.
// @ts-ignore
var isIE = !!document.documentMode;
Upvotes: 0
Reputation: 1668
I've used bracket notation to get rid of the error:
document['documentMode']
Upvotes: 24
Reputation: 164139
You can simply add it to the Document
interface:
interface Document {
documentMode?: any;
}
function isBrowserIE() {
return window.document.documentMode;
}
If you are using modules then you need to use global augmentation:
declare global {
interface Document {
documentMode?: any;
}
}
Upvotes: 19