A way to access the private _canvas on AdvanceDynamicTexture without Typescript having and Anyrisum?

So ts absolutely wont let me access the _canvas whereas then I can not access the getContext().

The reason I need to do this is I am trying to run an operation like this:

    textarea = advancedTexture._canvas.getContext('2d').measureText(text).width
    m = Math.round(Math.max(textarea, 0))    
    rect.width = ((h*2)+(m))+'px'

I tried to make a temp canvas and do the same operation but its being a pain and is kinda ugly, I have a sneaking suspicion thats gonna be what is the “solution”, but would like to hear other options for sure.

To make TS happy you can do:

textarea = (advancedTexture as any)._canvas.getContext('2d').measureText(text).width;

But you should be able to do:

textarea = advancedTexture.getContext().measureText(text).width;
1 Like

hmm I thought I tried that… thanks dude as always.