What is the correct version of the TypeScript compiler to use with Babylon 4.10.0?

1.) I upgraded my application’s package.json to the Babylon ‘4.10.0’ version using the TypeScript 3.4.5 compiler and did not encounter any TypeScript compile errors, and my app functioned nominally.

2.) I pulled the Babylon source, checked out 4.10.0 as a local branch, and checked what version of TypeScript compiler was used: "typescript": "~3.7.5"

3.) I changed my application’s package.json to match the above “~3.7.5” version and I get the TypeScript compile error shown below when trying pass a BABYLON.Mesh object to the API function:
Ray.intersectsMesh(mesh: DeepImmutable<AbstractMesh>, fastCheck?: boolean): PickingInfo

4.) I experimented until I found what version of TypeScript caused it to generate compile errors:

  • Using TypeScript 3.4.5, 3.5.2, and 3.5.3 I could pass the BABYLON.Mesh object without compile errors.
  • Using ‘3.6.1-rc’ <= Typescript version <= ‘3.9.3’ caused the compile error below.

Typescript Compile Error:

Error:(113, 65) TS2345: Argument of type 'Mesh' is not assignable to parameter of type 'DeepImmutableObject<AbstractMesh>'.
  Types of property '_internalAbstractMeshDataInfo' are incompatible.
    Type '_InternalAbstractMeshDataInfo' is not assignable to type 'DeepImmutableObject<_InternalAbstractMeshDataInfo>'.
      Types of property '_skeleton' are incompatible.
        Type 'Skeleton' is not assignable to type 'DeepImmutableObject<Skeleton>'.
          Types of property 'bones' are incompatible.
            Type 'Bone[]' is not assignable to type 'DeepImmutableArray<Bone>'.
              Types of property 'concat' are incompatible.
                Type '{ (...items: ConcatArray<Bone>[]): Bone[]; (...items: (Bone | ConcatArray<Bone>)[]): Bone[]; }' is not assignable to type '{ (...items: ConcatArray<DeepImmutableObject<Bone>>[]): DeepImmutableObject<Bone>[]; (...items: (DeepImmutableObject<Bone> | ConcatArray<DeepImmutableObject<Bone>>)[]): DeepImmutableObject<Bone>[]; }'.
                  Types of parameters 'items' and 'items' are incompatible.
                    Type 'ConcatArray<DeepImmutableObject<Bone>>' is not assignable to type 'ConcatArray<Bone>'.
                      Type 'DeepImmutableObject<Bone>' is missing the following properties from type 'Bone': _skeleton, _localMatrix, _restPose, _baseMatrix, and 28 more.

Pick Function using intersectsMesh()

PickMesh is one of my classes.

private mapToPickMesh(mesh: BABYLON.Mesh, toPoint: BABYLON.Vector3): PickMesh {
    const directionVector: BABYLON.Vector3 = this.camera.position.subtract(toPoint);
    const unitDirectionVector: BABYLON.Vector3 = BABYLON.Vector3.Normalize(directionVector);
    const ray: BABYLON.Ray = new BABYLON.Ray(toPoint, unitDirectionVector, directionVector.length());
    // BABYLON.RayHelper.CreateAndShow(ray, this.babylonjsCanvas.scene, new BABYLON.Color3(0, 1, 0));
    const pickingInfo: BABYLON.PickingInfo = ray.intersectsMesh(mesh); // COMPILE ERROR HERE
    return new PickMesh(mesh.name, pickingInfo, mesh);
  }

This is really strange and the latest version is using 3.8.3 whilst 4.1.0 was using 3.7.5.

Could you try to force a convertion from Mesh to DeepImmutableObject<Mesh> when calling in the function ?

Also if that does not work a quick repro on Github would help greatly.

With TypeScript 3.8.3 using the cast below suppresses the error. It appears to function normally.

const pickingInfo: BABYLON.PickingInfo = ray.intersectsMesh(<BABYLON.DeepImmutableObject<BABYLON.Mesh>><unknown>mesh);

IMO, THIS IS BROKEN if I have to use crazy casts like that.

Cannot reproduce on Playground. Sigh.

https://playground.babylonjs.com/#VB1Q52#1

My tsconfig.json:

{
  "compilerOptions": {
    "target": "es6",
    "module": "esnext",
    "moduleResolution": "node",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "removeComments": false,
    "noImplicitAny": false,
    "skipLibCheck": true,
    "suppressImplicitAnyIndexErrors": true,
    "outDir": "target/classes/static/app",
    "lib": ["es7", "dom"],
    "typeRoots": ["node_modules/@types"],
    "baseUrl": "./",
    "paths": {
      "app/*": ["src/main/webapp/app/*"]
    },
    "importHelpers": true,
    "allowJs": true
  },
  "include": ["src/main/webapp/app", "src/test/javascript/"],
  "exclude": ["node_modules"]
}

I am totally unable to repro on my side :frowning: so would be cool to have a none transpiling example on github ?

We have now moved to 3.9.5 for the main code.

@sebavan this still appears to be an issue. I am seeing it using tsc 3.9.7 and 4.1.2 - is anyone looking into fixing this?

  The types of '_internalAbstractMeshDataInfo._skeleton' are incompatible between these types.
    Type 'Nullable<Skeleton>' is not assignable to type 'DeepImmutableObject<Skeleton> | null'.
      Type 'Skeleton' is not assignable to type 'DeepImmutableObject<Skeleton>'.
        The types of 'bones.concat' are incompatible between these types.
          Type '{ (...items: ConcatArray<Bone>[]): Bone[]; (...items: (Bone | ConcatArray<Bone>)[]): Bone[]; }' is not assignable to type '{ (...items: ConcatArray<DeepImmutableObject<Bone>>[]): DeepImmutableObject<Bone>[]; (...items: (DeepImmutableObject<Bone> | ConcatArray<...>)[]): DeepImmutableObject<...>[]; }'.
            Types of parameters 'items' and 'items' are incompatible.
              Type 'ConcatArray<DeepImmutableObject<Bone>>' is not assignable to type 'ConcatArray<Bone>'.
                Type 'DeepImmutableObject<Bone>' is missing the following properties from type 'Bone': _skeleton, _localMatrix, _restPose, _bindPose, and 29 more.

214                 tl.intersectsMesh(canvas/* as DeepImmutableObject<AbstractMesh>*/);```

@jasowill does this still happen for you with the latest nightly ?

could you share a repro ?

Thanks for the suggestion @sebavan. Let me try with the latest build (I am currently using 4.2 in this build).

@sebavan unfortunately it still occurs with the latest 5.0.0-alpha.12. Let me try to sync the repo above and see if it repros there.

Perfect and if it continues please share a tiny repo highlighting the issue so that I can try to double check.

@sebavan I can’t repro it with a simple project! I guess we are in the clear on this one. For the time being I will use the workaround cast until I can figure out why this large rush project is exhibiting this issue. Thanks for the quick replies!

No problem let me know if anything else can be done once you have the issue back.