Skip to content

onBeforeRender in BatchedMesh causes TS error #310

Closed
@tehwalris

Description

@tehwalris
  • three version: 0.139.2
  • @types/three version: 0.139.0
  • three-stdlib version: 2.28.0

Problem description:

In a project that has three-stdlib as a dependency I see these errors when running TypeScript:

node_modules/.pnpm/three-stdlib@2.28.0_three@0.139.2/node_modules/three-stdlib/objects/BatchedMesh.d.ts:37:5 - error TS2425: Class 'Mesh<BufferGeometry, Material>' defines instance member property 'onBeforeRender', but extended class 'BatchedMesh' defines it as instance member function.

37     onBeforeRender(): void;
       ~~~~~~~~~~~~~~

node_modules/.pnpm/three-stdlib@2.28.0_three@0.139.2/node_modules/three-stdlib/objects/BatchedMesh.d.ts:38:5 - error TS2425: Class 'Mesh<BufferGeometry, Material>' defines instance member property 'onAfterRender', but extended class 'BatchedMesh' defines it as instance member function.

38     onAfterRender(): void;
       ~~~~~~~~~~~~~

Relevant code:

I'm just importing the library, not using it yet. That is enough to trigger the tsc error.

Suggested solution:

I noticed you have @ts-ignore above onBeforeRender in BatchedMesh. In the generated BatchedMesh.d.ts these @ts-ignore comments get stripped:

import { Matrix4, Mesh, BufferGeometry, Material, DataTexture, IUniform } from 'three';
declare class BatchedMesh extends Mesh<BufferGeometry, Material> {
    // ... (other methods omitted)
    onBeforeRender(): void;
    onAfterRender(): void;
}
export { BatchedMesh };

Since the @ts-ignore comment isn't helping here, we have to actually fix the original type error. To fix it we could either make onBeforeRender a property in three-stdlib or make it a method in @types/three. It would be nice to know why @types/three defined onBeforeRender as a property in the first place though.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions