-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Add types to shortcut #26175
Add types to shortcut #26175
Conversation
|
||
/** | ||
* @param {Props} props Props | ||
* @return {import('react').ReactNode} Element |
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.
Why the change to use ReactNode?
That seems to work in my testing, but this should really conform to JSXElementConstrcutor
.
type JSXElementConstructor<P> =
| ((props: P) => ReactElement | null)
| (new (props: P) => Component<P, any>);
The FunctionComponent
type also returns ReactElement | null
. (JSX.Element
just extends ReactElement, so JSX.Element | null
is also good)
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.
I thought ReactNode
was preferable as a single type, I didn't realize what the exact interface functional components adhered to. I'll change this back to JSX.Element | null
👍
} | ||
|
||
if ( isObject( shortcut ) ) { |
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 change concerns me a bit… we only expect to receive a string or object, but this protected against other values before and doesn't after this change.
How do you feel about reverting it?
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.
I will becuase I cannot reproduce the reason I made this change to begin with 🤦♀️ There was some issue with refining the type down to an object with the two properties, but it's working now, go figure.
This looks good but it needs a rebase. |
I'll reopen this PR in a second. |
Description
Add types to
Shortcut
and update type-refinements in the component.How has this been tested?
Local typecheck.
Types of changes
Type updates.
Checklist:
/cc @sirreal