Skip to content
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

Closed
wants to merge 4 commits into from
Closed

Add types to shortcut #26175

wants to merge 4 commits into from

Conversation

sarayourfriend
Copy link
Contributor

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:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR.

/cc @sirreal

@sirreal sirreal added [Package] Components /packages/components [Type] Code Quality Issues or PRs that relate to code quality npm Packages Related to npm packages labels Oct 15, 2020
@sirreal sirreal requested review from sirreal and ockham October 15, 2020 22:19

/**
* @param {Props} props Props
* @return {import('react').ReactNode} Element
Copy link
Member

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)

Copy link
Contributor Author

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 👍

Comment on lines 16 to 18
}

if ( isObject( shortcut ) ) {
Copy link
Member

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?

Copy link
Contributor Author

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.

@sirreal
Copy link
Member

sirreal commented Oct 22, 2020

This looks good but it needs a rebase.

@sarayourfriend sarayourfriend deleted the add/types-to-shortcut branch October 22, 2020 21:08
@sarayourfriend sarayourfriend restored the add/types-to-shortcut branch October 22, 2020 21:21
Base automatically changed from master to trunk March 1, 2021 15:44
@sarayourfriend
Copy link
Contributor Author

I'll reopen this PR in a second.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
npm Packages Related to npm packages [Package] Components /packages/components [Type] Code Quality Issues or PRs that relate to code quality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants