Possible TS definition bug or incorrect use

I’m having some trouble getting past my linter. I recently forced my project to being more strict gasps which caused one of my Babylon components to screech to a halt. I’m working with StandardMaterial like so:

const material = new StandardMaterial('AM', this._scene);
material.emissiveColor = Color3.White();
material.roughness = 1;
// Apply different effects based on substrate
switch (type) {
  case Substrate.Canvas:
    material.diffuseTexture = new Texture(url, this._scene);
    material.detailMap.isEnabled = true;
    material.detailMap.texture = new Texture(
      `${this.assetBase}/textures/substrate_canvas.png`, this._scene
    material.detailMap.texture.uScale = 3;
    material.detailMap.texture.vScale = 3;
    material.detailMap.diffuseBlendLevel = 0.4;
    material.detailMap.bumpLevel = 0.5;

The code itself works ie. somehow the detailMap gets applied and adjusted (I know this from disabling the linter). It also creates the effect that I want. The code is based on some examples I found. However when I add the linting in, it’s starts complaining:

TypeError: Cannot set property 'isEnabled' of undefined

There’s an 80% chance I’ve done some wildly wrong ie. I suspect detailMap was moved in a release and the doc/example I read is old OR perhaps the type definitions in TS are causing troubles? It’s just strange that my texture does end up being correct.

I’m on BJS 4.1.0

This is because material.detailMap is Nullable. so you should use this code:

material.diffuseTexture = new Texture(url, this._scene);
    material.detailMap!.isEnabled = true;
    material.detailMap!.texture = new Texture(
      `${this.assetBase}/textures/substrate_canvas.png`, this._scene
    material.detailMap!.texture.uScale = 3;
    material.detailMap!.texture.vScale = 3;
    material.detailMap!.diffuseBlendLevel = 0.4;
    material.detailMap!.bumpLevel = 0.5;

(note the bangs)

Thanks for the super fast response, I did try that and it still complains.

Property 'detailMap' does not exist on type 'StandardMaterial'.  TS2339

Even getting warnings from VSCodium.

well I think you do not have the right d.ts then

I’m just importing Babylon properly as I normally would. Is there something else I should be using? confused

I found these types: @types/babylonjs - npm but as the deprecation notice says it should be included in the regular package import.

it is in the package (at least for 4.2) which version are you importing?

I thought 4.1.0 had it, I had to directly install 4.2.0 beta 6 to get the right types. Sigh.

That solved it. Sorry for the silliness. :stuck_out_tongue:

1 Like