Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

TypeError: "x.write" is not a function

PanelRenderer.rendererBody = function (oR, oItem) {
        const sText= oItem.getText();
        if (sText) {
            oR.write("<h1>");
            oR.write("</h1>");
            oR.writeBack(sText);

        }
    };
PanelRenderer.render = function (oR, oItem) {
        this.start(oR, oItem);
        this.rendererBody(oR, oItem);
        this.end(oR);
    };

I cannot reproduce this error so I would like to ask any possible reasons of this type error
This error is in the compiled version.

What I thought was undefined, so put ?. in front of write function like oR?.write( )
But not sure cause i cannot reproduce it.

And how can I fix if it cannot be reproduced?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

If you see that message randomly, at (at least) one point in your code something is passed as first parameter (ie as oR) to your render (and therefore also rendererBody) function, that doesn’t have the correct type, and thus does not have a write function.

Typescript can only assure compile time type safety. Ie, when the data at runtime differs from the expected data, there is nothing typescript can do about it.

Fixing might be hard, if it’s not (reliably) reproducible. You can only check where your render (or rendererBody) is called, and see where the data you pass into that function comes from and if it by any chance might not be, what you expect it to be.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading