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
What changes are introduced?
I changed some TS typing information related to custom schema component props.
Why are these changes introduced?
It intends to fix some TS type errors.
What issue(s) does this solve? (with link, if possible)
The changes were to address something like this:
I initially tried using the broader
FieldProps
type forprops
parameter but trying to useprops.value?.current
gives this TS error:So I changed it to use the more specific
ObjectFieldProps<SlugValue>
props value, however this had the issue where thecurrent
value is set asunknown
even though it's type should be known viaSlugValue
type.I changed the
ObjectFieldProps
definition to apply theT
template variable type to thevalue
object so that it's type can be inferred based on the provided Object type (SlugValue
in this case).What to review
The changes only apply to TS error messages related to custom schema components' field props. The example above should be good enough to reproduce the issue, just adding this to your schema. The example above includes some components from
@sanity/ui
as is described in the docs.Testing
I didn't really test beyond my specific use case with
ObjectFieldProps<SlugValue>
. Someone should probably have a look that these changes apply properly to the rest of theFieldProps
generic type options:Apologies if I've done this wrong. I don't typically send out pull requests like this 🤷 ✌️