Skip to content

fix(three): add missing readonly Material.id declaration - #2496

Merged
Methuselah96 merged 7 commits into
three-types:masterfrom
Yuren0312:fix-material-id
Oct 20, 2026
Merged

Methuselah96 merged 7 commits into
three-types:masterfrom
Yuren0312:fix-material-id

Conversation

@Yuren0312

Copy link
Copy Markdown
Contributor

Summary

Fixes #2422 — Material.id is missing from the type declarations (TS2339: Property 'id' does not exist on type 'MeshBasicMaterial'), a regression since 0.178.

Root cause

Material declares its id in the constructor with Object.defineProperty( this, 'id', { value: _materialId ++ } ); (the same pattern Object3D uses). Unlike Object3D and Texture, the Material declaration file never carried the member, so the property is invisible to TypeScript.

Changes

  • types/three/src/materials/Material.d.ts: add readonly id: number to the Material class, with a JSDoc comment mirroring the runtime (@name Material#id, @type {number}, @readonly) and the chronological-id remark used by Object3D.
  • types/three/test/unit/src/materials/Material.ts: new unit test asserting material.id is a number ($ExpectType) and that assigning to it is a compile error (@ts-expect-error).
  • types/three/tsconfig.json: register the new test file.

Verification

  • tsc --noEmit against the new test passes with the fix in place.
  • Negative control: with the declaration removed again, the test fails with exactly the error from the issue (TS2339: Property 'id' does not exist on type 'MeshBasicMaterial').
  • Formatting follows the repo's dprint config (4-space indent, 120 line width) and matches the Object3D/Texture declaration style.

I could not run the full pnpm run test (dtslint) locally — it needs the pnpm workspace install — so the unit test was validated with tsc directly using the same compiler options as types/three/tsconfig.json (plus @types/webxr for the ambient XR types dtslint provides).

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.

@Methuselah96 Methuselah96 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Methuselah96 and others added 2 commits October 20, 2026 18:47
# Conflicts:
#	jsdoc-testing/changes.patch
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Methuselah96
Methuselah96 merged commit de99cbc into three-types:master Oct 20, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Material.id is missing — declaration emit doesn't see Object.defineProperty members

2 participants