Fix StandardMaterial property types in the generated .d.ts - #9163
Fix StandardMaterial property types in the generated .d.ts#9163willeastcott wants to merge 1 commit into
Conversation
StandardMaterial defines its accessors dynamically, so tsc emits none of
them. They are declared by hand from STANDARD_MAT_PROPS in the types fixup
plugin, and each doc comment was looked up with
contents.match(`@property {${type}} ${name}`) - passing the type through as
a regex. That one line caused three distinct defects:
- When the type in the list disagreed with the type in the class JSDoc, the
lookup silently found nothing, so the accessor was emitted with no doc
comment and with the (wrong) type from the list. occludeDirect was typed
`number` despite defaulting to `false`, so `material.occludeDirect = true`
needed a @ts-ignore from TypeScript. alphaFade had the same problem in
reverse, typed `boolean` despite being _defineFloat('alphaFade', 1).
- `Texture|null` was treated as a regex alternation, matching "@Property
{Texture" at its first occurrence in the file and then slicing from the
wrong offset. Every texture property inherited a mangled fragment of
diffuseMap's description, e.g. anisotropyMap documented as "e main
(primary) diffuse map of the material (default is null)."
- "@Property {number} anisotropy" prefix-matched anisotropyIntensity, so the
deprecated alias inherited its neighbour's documentation.
Fixes:
- occludeDirect is now `boolean` and alphaFade `number`, matching their
runtime defaults.
- opacityShadowDither's JSDoc said `boolean` for what is a dither mode
string (DITHER_NONE etc.); the emitted declaration was already correct, so
the JSDoc is corrected to `string`.
- The doc lookup now parses the @Property block into a map keyed by property
name, rather than building a regex out of the type.
- The build throws on a type disagreement or a missing @Property tag, so
this cannot silently regress into a dropped doc comment again.
- Added the missing @Property tag for sheenVertexColorChannel, and an
explicit @deprecated doc for the anisotropy alias.
Every StandardMaterial accessor now emits with its own correct doc comment.
Fixes #9152
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Build size reportThis PR does not change the size of the minified bundles.
|
Public API reportThis PR changes the public API surface (+2 / −1), per the docs' rules (@ignore / @Private / undocumented are excluded). Show API diff-StandardMaterial.opacityShadowDither: boolean
+StandardMaterial.opacityShadowDither: string
+StandardMaterial.sheenVertexColorChannel: stringInformational only — this never fails the build. |
There was a problem hiding this comment.
🟢 Approval recommended
The changes are narrowly scoped to declaration generation and JSDoc alignment, and no functional runtime behavior is modified.
Pull request overview
This PR fixes TypeScript declaration generation for StandardMaterial by making the rollup types fixup plugin reliably pull per-property JSDoc (without regex pitfalls) and by correcting a few mismatched property types/documentation so the emitted .d.ts matches runtime behavior.
Changes:
- Corrected
StandardMaterialproperty types in the generated declarations (occludeDirect→boolean,alphaFade→number). - Reworked
StandardMaterialJSDoc lookup inrollup-types-fixup.mjsto parse@propertytags into a name-keyed map and to throw on missing/mismatched tags. - Updated
StandardMaterialclass JSDoc to add the missingsheenVertexColorChanneltag and fixopacityShadowDither’s documented type tostring.
File summaries
| File | Description |
|---|---|
| utils/plugins/rollup-types-fixup.mjs | Fixes StandardMaterial accessor .d.ts emission by parsing JSDoc properties reliably and enforcing type/tag consistency. |
| src/scene/materials/standard-material.js | Aligns class-level @property docs with runtime and the generated .d.ts (added/mended tags). |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| ['alphaFade', 'number'], | ||
| ['ambient', 'Color'], | ||
| ['anisotropy', 'number'], | ||
| ['anisotropy', 'number', 'Defines amount of anisotropy. @deprecated Use {@link StandardMaterial#anisotropyIntensity} and {@link StandardMaterial#anisotropyRotation} instead.'], |
|
Superseded by #9295, which fixes the same two type errors (alphaFade is now number, occludeDirect is now boolean) and replaces the regex-based description lookup with a plain string search, so the Texture|null alternation no longer mangles the texture-map doc comments. The JSDoc side of this branch (opacityShadowDither typed as string, sheenVertexColorChannel documented) landed in #9294. The one piece not carried over is the build-time check that the hand-declared list agrees with the @Property tags; that can be revisited separately if wanted. |
Description
StandardMaterialdefines its accessors dynamically, so tsc emits none of them — they are declared by hand fromSTANDARD_MAT_PROPSinutils/plugins/rollup-types-fixup.mjs. Each doc comment was looked up withcontents.match(`@property {${type}} ${name}`), passing the type through as a regex. That one line caused three distinct defects.1. Type disagreements silently dropped the doc comment and emitted the wrong type. When the type in the list disagreed with the class JSDoc, the lookup found nothing, so the accessor was emitted with an empty doc comment and the (wrong) type from the list:
.d.tsoccludeDirectnumberfalsebooleanalphaFadeboolean1(_defineFloat)numberBoth broke the correct assignment from TypeScript:
occludeDirectis the one reported in #9152;alphaFadeis the same defect found by generalizing it.2.
Texture|nullwas treated as a regex alternation. It matched@property {Textureat its first occurrence in the file and then sliced from the wrong offset, so every texture property inherited a mangled fragment ofdiffuseMap's description:3.
@property {number} anisotropyprefix-matchedanisotropyIntensity, so the deprecated alias inherited its neighbour's documentation.Changes
occludeDirect→boolean,alphaFade→number, matching their runtime defaults.opacityShadowDither's JSDoc saidbooleanfor what is a dither mode string (DITHER_NONE/DITHER_BAYER8/…). The emitted declaration was already correct, so the JSDoc is corrected tostring— its siblingopacityDitherwas already documented correctly.@propertyblock into a map keyed by property name instead of building a regex out of the type. This restores the correct description on ~30 texture properties and onanisotropy.@propertytag, so this cannot silently regress into a dropped doc comment again:@propertytag forsheenVertexColorChannel(verified'rgb'at runtime) and an explicit@deprecateddoc for theanisotropyalias.Every
StandardMaterialaccessor now emits with its own correct doc comment — previouslyoccludeDirect,opacityShadowDither,alphaFadeandsheenVertexColorChannelhad none at all.Fixes #9152
Notes for reviewers
guardno longer encodes a type (set alphaFade(arg: boolean);→set alphaFade(arg:), so it won't need updating the next time a type changes. Re-runningbuild:typesis idempotent — verified..d.tsat all (thickness,attenuation,sheenGloss,alphaDither, and all the iridescence/refraction ones) — the hand-maintained list holds 184 entries against 233@propertytags. That's missing declarations rather than wrong ones, and adding 49 entries would swamp this change, so it is deliberately left out.Testing
npm run build:types→npm run test:typesclean.--strict, withoccludeDirect = 1andalphaFade = truestill correctly rejected (asserted via@ts-expect-error).npm run lintclean.npm test: 2044 passing / 11 failing — identical with the changes stashed. The 11 are pre-existing asset-loading timeouts in the font/sprite handler tests, unrelated to this change.Checklist