Solution 1 :

Because according to TS DOM typings, write only exists on Document type.
Maybe it worth updating TS version, maybe not)

There is one fast workaround:

let doc = (this.iframe.contentDocument || this.iframe.contentWindow) as Document;

Please, double check if write method exists in case this.iframe.contentDocument === null // true

Problem :

Doing the following:

    let doc = this.iframe.contentDocument || this.iframe.contentWindow;
    let content = `...`
    doc!.open();
    doc!.write(content);
    doc!.close();

However the Typescript linter says:

Property ‘write’ does not exist on type ‘Document | Window’.
Property ‘write’ does not exist on type ‘Window’.ts(2339)

How do we fix that?

Comments

Comment posted by abhishek khandait

typecase doc to

By