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

chore: DocsPage to TypeScript #337

Merged
merged 7 commits into from
Sep 15, 2021
Merged

Conversation

thiskevinwang
Copy link
Contributor

@thiskevinwang thiskevinwang commented Sep 14, 2021

🎟️ Asana Task
πŸ” Preview Link


Description

This converts DocsPage to TypeScript;

No new changes to the component API!

PR Checklist πŸš€

Items in this checklist may not may not apply to your PR, but please consider each item carefully.

  • Add Asana and Preview links above.
  • Conduct thorough self-review.
  • Add or update tests as appropriate.
  • Conduct reasonable cross browser testing for both compatibility and responsive behavior (We have a Sauce Labs account for this, if you don't have access, just ask!).
  • Conduct reasonable accessibility review (use the WAS as a guide or an axe browser plugin until we establish more formal checks).
  • Identify (in the description above) and document (add Asana tasks on this board) any technical debt that you're aware of, but are not addressing as part of this PR.

@changeset-bot
Copy link

changeset-bot bot commented Sep 14, 2021

πŸ¦‹ Changeset detected

Latest commit: 98e21c7

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@hashicorp/react-docs-page Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link

vercel bot commented Sep 14, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

πŸ” Inspect: https://vercel.com/hashicorp/react-components/Ucq7axZsYbnGRTPxoTdxUBrTjBkL
βœ… Preview: https://react-components-git-kevin-versionselect-into-31789e-hashicorp.vercel.app

@thiskevinwang thiskevinwang requested a review from a team September 14, 2021 17:15
Copy link
Contributor

@BRKalow BRKalow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good!

}
}

const DocsPage: ComponentType<DocsPageProps> = ({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As DocsPage doesn't accept children, I'm not sure it makes sense to use ComponentType here, which defines props as PropsWithChildren<DocsPageProps>. I would maybe just type props here:

export default function DocsPage({ ... }: DocsPageProps) {

ref: https://sourcegraph.com/github.com/DefinitelyTyped/DefinitelyTyped/-/blob/types/react/index.d.ts?L82:10

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'll opt for your suggestion, but will need to add an explicit return type : JSX.Element

We have a linting rule β€” Missing return type on function. eslint@typescript-eslint/explicit-module-boundary-types β€” that warns if you don't have an explicit return type.

  • πŸ’­ Maybe we should re-assess this rule? Type-inference is pretty good, and sometimes explicit typing is prone to human error β€” 0 warnings, but incorrect type

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yeah, that rule! I think the value of that rule is debatable for react components, but it can be handy for other methods. We have had a few discussions about this rule in the past πŸ’­ cc @hashicorp/web-platform

I think the return type should be React.ReactElement, FWIW. This matches the definition of the component types from @types/react.

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 was looking at React.ReactElement (from the Sourcegraph link) ... vs. JSX.Element (from type-hint/inference) πŸ˜…

I'll update to React.ReactElement!

packages/docs-page/index.tsx Outdated Show resolved Hide resolved
packages/docs-page/index.tsx Outdated Show resolved Hide resolved
) {
productName: string,
additionalComponents: MDXProviderComponentsProp = {}
): Record<string, string> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

defaultMdxComponents returns a map of string to components I think πŸ’­

https://github.com/hashicorp/nextjs-scripts/blob/main/packages/docs-mdx/index.jsx#L11

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'll do:

Record<string, (p: any) => JSX.Element>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to

Record<string, (p: any) => ReactElement>

- improve DocsPage typing
- enable `className` prop on SearchBar
const isMobile = useIsMobile()

return (
<Search
className={className}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸ’―

Copy link
Contributor

@BRKalow BRKalow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸ₯‡

@thiskevinwang thiskevinwang merged commit 40afe45 into main Sep 15, 2021
@thiskevinwang thiskevinwang deleted the kevin/versionselect-into-docspage branch September 15, 2021 16:24
@github-actions github-actions bot mentioned this pull request Sep 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants