1

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?

1
  • typecase doc to any. let doc = (this.iframe.contentDocument || this.iframe.contentWindow) as any; Commented Dec 4, 2020 at 14:09

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.