feat: Add ShaderMaterial uniforms typing and autocompletion (+ ShaderPass) #151
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.
Why
To increase quality and speed of development. With autocompletion you won't misspell uniform names and mistype their values.
What
Added uniforms typings for ShaderMaterial, RawShaderMaterial and ShaderPass and also overall type improvements.
The uniform types are automatically inferred when creating an instance from parameters.
Or they can be supplied in generic (useful when just declaring variables) in multiple ways:
The uniform types will be asserted while creating an instance.
In
ShaderMaterial.d.ts
you can also find a more strict variant for uniforms (which is commented out) for the case when you don't supply types during declaration, meaning uniforms themselves can be undefined (as there's no assertion during instance creation) or when you cast Material to ShaderMaterial which produces a correct type error but due to the fact this practice is used everywhere in legacy code I decided not to keep it and leave it more loosely making it fully backwards compatible.Also as
null
a separate type it's recommended to type uniforms the following way:Because if it's simply a
null
it will be replaced byany
to allow value modification.Checklist