pmndrs / three-stdlib

📚 Stand-alone library of threejs examples designed to run without transpilation in node & browser
https://npmjs.com/three-stdlib
MIT License
704 stars 117 forks source link

`onBeforeRender` in `BatchedMesh` causes TS error #310

Closed tehwalris closed 11 months ago

tehwalris commented 11 months ago

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.

tehwalris commented 11 months ago

This issue was introduced in #307.

github-actions[bot] commented 11 months ago

:tada: This issue has been resolved in version 2.28.1 :tada:

The release is available on:

Your semantic-release bot :package::rocket: