-
-
Notifications
You must be signed in to change notification settings - Fork 924
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revised Component types (children, ref) (#877)
* Revised Component types (children, readonly, ref) * Rename past `Component` type to `ComponentWithChildren`. Motivation: Most components don't actually support children. This causes a type error upon accidental passing of children / forces you to think about which components support children. * Added second parameter to `ComponentWithChildren` to make it easier to give a custom type for `children` (but still defaults to useful `JSX.Element`). * New `Component` type does not have automatic `children` property (like React's preferred `VoidFunctionalComponent`), offering another natural way to type `props.children`: `Component<{children: JSX.Element}>`. * `props` argument in both `Component` and `ComponentWithChildren` automatically cast to `readonly` (shallow one level only), to avoid accidental assignment to `props.foo` (usually a getter) while still allowing passing mutables in props. Add `Props<T>` helper for this transformation. * Add @lxsmnsyc's `Ref<T>` type so it's easy to type `props.ref`: `Component<{ref: Ref<Element>}>`. <#778 (comment)> Fixes #778. * Fix test * Remove Props helper and shallow Readonly for props * VoidComponent, ParentComponent, FlowComponent * Use Component<any> for generic component type * Add default types, Context.Provider require children Comments from Otonashi * Default parameter for PropsWithChildren * Restore missing <any> * Docs typo fix * Cleanup server code * JSDoc improvements * Improve FlowProps JSDoc * More FlowComponent JSDoc improvements Co-authored-by: Ryan Carniato <[email protected]>
- Loading branch information
Showing
4 changed files
with
84 additions
and
14 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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