Repository navigation
fix(three): add missing readonly Material.id declaration - #2496
Merged
Merged
Conversation
Material declares its id via Object.defineProperty() in the constructor (the same pattern Object3D uses), but the declaration file never carried the member, so `material.id` fails with TS2339 since 0.178. Restore the readonly id property, matching the runtime and the Object3D/Texture declarations. Fixes three-types#2422.
Asserts `material.id` is a number and that assigning to it is a compile error, guarding against the regression in three-types#2422.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts: # jsdoc-testing/changes.patch
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #2422 —
Material.idis missing from the type declarations (TS2339:Property 'id' does not exist on type 'MeshBasicMaterial'), a regression since 0.178.Root cause
Materialdeclares its id in the constructor withObject.defineProperty( this, 'id', { value: _materialId ++ } );(the same patternObject3Duses). UnlikeObject3DandTexture, theMaterialdeclaration file never carried the member, so the property is invisible to TypeScript.Changes
types/three/src/materials/Material.d.ts: addreadonly id: numberto theMaterialclass, with a JSDoc comment mirroring the runtime (@name Material#id,@type {number},@readonly) and the chronological-id remark used byObject3D.types/three/test/unit/src/materials/Material.ts: new unit test assertingmaterial.idis anumber($ExpectType) and that assigning to it is a compile error (@ts-expect-error).types/three/tsconfig.json: register the new test file.Verification
tsc --noEmitagainst the new test passes with the fix in place.TS2339: Property 'id' does not exist on type 'MeshBasicMaterial').Object3D/Texturedeclaration style.I could not run the full
pnpm run test(dtslint) locally — it needs the pnpm workspace install — so the unit test was validated withtscdirectly using the same compiler options astypes/three/tsconfig.json(plus@types/webxrfor the ambient XR types dtslint provides).