Fix StandardMaterial property types in the generated .d.ts - #9163
Draft
willeastcott wants to merge 1 commit into
Draft
Fix StandardMaterial property types in the generated .d.ts#9163willeastcott wants to merge 1 commit into
willeastcott 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. |
willeastcott
marked this pull request as draft
August 12, 2026 20:15
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.
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