fix: improve types for rendered components props for ReactRenderer #6843
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.
Changes Overview
This PR improves the TypeScript types for the ReactRenderer to provide better type safety and autocompletion for the rendered component props.
Previously, the rendered component props were typed as
Record<string, any>, which allowed for common errors like typos or incorrect prop value types to go unnoticed by the compiler. This change ensures that any props passed to theReactRendererare correctly validated against the rendered component's actual prop types, leading to a more robust developer experience.Implementation Approach
The implementation introduces a generic type parameter
Pto theReactRendererclass andReactRendererOptionsinterface.This generic
P, representing the rendered component's props, is used to strictly type the props object in the constructor.The
updatePropsmethod is now typed to acceptPartial<Omit<P, 'ref'>>, ensuring type-safe partial updates and preventing the internally-managedrefprop from being overwritten.The constructor logic is updated to handle cases where props might be
undefined, mostly to avoid type casting in the constructor declaration.Testing Done
As this is a type-only change, no runtime behavior is altered. All existing unit and integration tests continue to pass. The primary validation for this change is through TypeScript's static analysis, which now correctly identifies type errors at compile time when using the ReactRenderer.
Verification Steps
A verification test was done in a consuming project locally by installing the
@tiptap/reactpackage viapnpm add file:<path to clone>/packages/react. The improved types worked as expected when autocompleting and inspecting them.Additional Notes
Checklist
- [ ] I have added tests where applicable.Related Issues