-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update types and props for compatibility with React 18 #7150
Conversation
Fixes type error in NonContiguousDayRangePicker related to react-day-picker Caption component prop: ``` Type 'FC<CaptionProps>' is not assignable to type '(props: CaptionProps) => Element | null'. Type 'ReactNode' is not assignable to type 'Element | null'. Type 'undefined' is not assignable to type 'Element | null'. ```
This reverts commit 77bf286.
This reverts commit 67a68f9.
@@ -24,7 +24,7 @@ import { H4 } from "../html/html"; | |||
|
|||
import { Hotkey, type HotkeyProps } from "./hotkey"; | |||
|
|||
export interface HotkeysProps extends Props { | |||
export interface HotkeysProps extends Props, React.PropsWithChildren<object> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like we're expecting children to be React.ReactElement<HotkeyProps>
. Should we use that type over object
?
(child: React.ReactElement<HotkeyProps>) => child.props, |
Or was the goal to preserve the same type definition of HotkeyProps
and avoid compile breaks on consumers?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one is a nitpick, but I've personally been avoiding React.PropsWithChildren<...>
since I see the React docs usually write the children
prop directly.
https://react.dev/learn/typescript#typing-children
Having the children
prop directly in the interface also makes it easier to add a JSDoc on the field.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -36,7 +36,7 @@ export interface ColumnWidths { | |||
defaultColumnWidth: number; | |||
} | |||
|
|||
export interface ColumnHeaderProps extends HeaderProps, ColumnWidths, ColumnIndices { | |||
export interface ColumnHeaderProps extends React.PropsWithChildren<HeaderProps>, ColumnWidths, ColumnIndices { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick: Similar comment around potentially writing the children
field directly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Invalidated by push of 21a62fc
Fixing type error: ``` ../table/src/cell/editableCell.tsx:198:17 - error TS2322: Type 'Element' is not assignable to type '(ReactElement<HotkeyProps, string | JSXElementConstructor<any>>[] & (boolean | ReactChild | ReactFragment | ReactPortal | null)) | undefined'. Type 'ReactElement<any, any>' is not assignable to type 'ReactElement<HotkeyProps, string | JSXElementConstructor<any>>[] & ReactPortal'. Type 'ReactElement<any, any>' is missing the following properties from type 'ReactElement<HotkeyProps, string | JSXElementConstructor<any>>[]': length, pop, push, concat, and 29 more. 198 <Hotkey ~~~~~~~ 199 key="edit-cell" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ... 203 onKeyDown={this.handleEdit} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 204 /> ~~~~~~~~~~~~~~~~~~ ../core/lib/esm/components/hotkeys/hotkeys.d.ts:17:5 17 children?: Array<React.ReactElement<HotkeyProps>>; ~~~~~~~~ The expected type comes from property 'children' which is declared here on type 'IntrinsicAttributes & IntrinsicClassAttributes<Hotkeys> & Pick<Readonly<HotkeysProps> & Readonly<...>, "className" | "children"> & InexactPartial<...> & InexactPartial<...>' ../table/src/table.tsx:504:25 - error TS2322: Type '(Element | Element[] | undefined)[]' is not assignable to type '(ReactElement<HotkeyProps, string | JSXElementConstructor<any>>[] & (boolean | ReactChild | ReactFragment | ReactPortal | null)) | undefined'. Type '(Element | Element[] | undefined)[]' is not assignable to type 'ReactElement<HotkeyProps, string | JSXElementConstructor<any>>[]'. Type 'Element | Element[] | undefined' is not assignable to type 'ReactElement<HotkeyProps, string | JSXElementConstructor<any>>'. Type 'undefined' is not assignable to type 'ReactElement<HotkeyProps, string | JSXElementConstructor<any>>'. 504 return <Hotkeys>{hotkeys.filter(element => element !== undefined)}</Hotkeys>; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../core/lib/esm/components/hotkeys/hotkeys.d.ts:17:5 17 children?: Array<React.ReactElement<HotkeyProps>>; ~~~~~~~~ The expected type comes from property 'children' which is declared here on type 'IntrinsicAttributes & IntrinsicClassAttributes<Hotkeys> & Pick<Readonly<HotkeysProps> & Readonly<...>, "className" | "children"> & InexactPartial<...> & InexactPartial<...>' ```
Switch to React.ReactNode for HotkeysProps children declarationBuild artifact links for this commit: documentation | landing | table | demoThis is an automated comment from the deploy-preview CircleCI job. |
Copied from React 18 Upgrade feature branch #7142
Proposed changes:
Updates types for forward compatibility with React 18.