Type for Typescript in Babylon.js 5.0

I already upgrade my code from 4.2 to 5.0. Everything fine except Typescript compiling error.
when I try to fix them I was found Babylonjs move some global namespace type (or it was inference by typescript) to internal namespace type (error from I use property doesn’t exist in internal type but actually exist).
My question is Why doesn’t Babylonjs use global namespace type? It should make better intellisense for editor and reduce maintenance effort.
Example for types that I thought should use from global namespace instead.

  • ICanvasRenderingContext > CanvasRenderingContext2D
  • ICanvas > HTMLCanvasElement
  • IImage > HTMLImageElement
  • etc.

cc @RaananW

1 Like

Hi,

Can I ask what package are you using and what version of the package?

We are augmenting the global namespace with the following declarations:
Babylon.js/packages/dev/core/src/LibDeclarations at master · BabylonJS/Babylon.js (github.com)

The augmentation of elements like the Image (HTMLImageElement) depends on your typescript version, but AFAIK all of the elemenets contained in the IImage inteface is already included in the HTMLImageElement, at least in the typescript version we are using.

We are augmenting elements like the HTMLCanvasElement or CanvasRenderingContext2D with missing parameters (here - Babylon.js/browser.d.ts at master · BabylonJS/Babylon.js (github.com)).

What parameters are you missing from those types?

Here my problem code I use property textBaseline from CanvasRenderingContext2D but missing in ICanvasRenderingContext

renderer.ts on line 71

Babylonjs property missing in type ICanvasRenderingContext · GitHub

I use @babylonjs/core 5.0.3 from NPM.

We have abstracted some of our interface because we share code with babylon native, that doesn’t have any HTML elements. The casting you are doing is the right way to go - case to the right typescript type and continue using it as you used it until today.

1 Like

I see. thank you.