Skip to content

chore: install and configure TypeScript #287

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

Merged
merged 2 commits into from
Jul 24, 2022

Conversation

WesSouza
Copy link
Member

This PR installs and configures TypeScript across our use cases.

This:

  • Configures TypeScript and dependencies
  • Configures Rollup to use TypeScript via esbuild and `rollup-plugin-dts
  • Configure Storybook so docs are generated from types
  • Configure ESLint
  • Configure Jest using ts-jest
  • Fix or ignore all ESLint issues
  • Fix a failing test
  • Converts Anchor to TypeScript

So far this is an incremental approach that allows JS and TS files to coexist.

I haven't checked if the output of esbuild is equivalent to the prior babel usage. I also haven't checked if we can remove babel from our explicit dependencies.

@vercel
Copy link

vercel bot commented Jul 21, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
react95 ✅ Ready (Inspect) Visit Preview Jul 24, 2022 at 4:02PM (UTC)


const Anchor = forwardRef<HTMLAnchorElement, AnchorProps>(function Anchor(
Copy link
Member Author

Choose a reason for hiding this comment

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

We need to replace React.forwardRef with forwardRef, otherwise props are not correctly captured by react-docgen-typescript.

};

export default Anchor;
export { Anchor, AnchorProps };
Copy link
Member Author

Choose a reason for hiding this comment

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

Storybook recommends not exporting the component as default:

If you run into an issue where any additional props don't show up, check your component's code. If you're using a default export, change it to a named export, and doing that will ensure that the additional props are included.

https://storybook.js.org/docs/react/configure/typescript

@codesandbox-ci
Copy link

codesandbox-ci bot commented Jul 21, 2022

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 754b321:

Sandbox Source
React95 template Configuration

@WesSouza
Copy link
Member Author

@arturbien @luizbaldi I paused work on this to get some feedback from y'all:

  • Can you validate if the output of Rollup using esbuild is equivalent to using babel and the other plugins?
  • We could release TypeScript support incrementally. Would that be ok or do we want to work on a separate branch and bundle it all on a new version?

@@ -13,6 +13,11 @@ import {
WindowContent
} from 'react95';

const Wrapper = styled.div`
Copy link
Member

Choose a reason for hiding this comment

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

Please remove these type of changes from this PR (moving Wrapper in stories to the top etc)

Copy link
Member Author

Choose a reason for hiding this comment

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

Some components have Wrapper defined above the export already.

This was done to fix no-use-before-define errors, would you want to disable those rules?

Copy link
Member

Choose a reason for hiding this comment

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

oh ok, I didn't notice we enforced this rule. If that's the case let's keep the changes!

@arturbien
Copy link
Member

@WesSouza I've noticed that prop type table is not generated for anchor component:
Screenshot 2022-07-24 at 13 30 31

How it looks on prod:
Screenshot 2022-07-24 at 13 30 45

@WesSouza
Copy link
Member Author

@arturbien I tested adding more props and those appear, but not children. I wonder if that's expected from that addon.

@arturbien
Copy link
Member

@WesSouza let's try to collapse the commits to a fewer ones where possible and change the last commit type to feat(anchor) so that semantic-release releases updated version with typed anchor

@WesSouza WesSouza force-pushed the typescript branch 2 times, most recently from aa7a331 to d20ebfc Compare July 24, 2022 12:32
@WesSouza WesSouza changed the base branch from master to beta July 24, 2022 12:58
@WesSouza WesSouza marked this pull request as ready for review July 24, 2022 12:59
@WesSouza WesSouza requested a review from arturbien July 24, 2022 12:59
@WesSouza WesSouza mentioned this pull request Jul 24, 2022
46 tasks
WesSouza added 2 commits July 24, 2022 12:01
This commit:
- Adds .editorconfig file
- Installs TypeScript and necessary dependencies
- Configures TypeScript tsconfig.json
- Configures Rollup to use esbuild and export .d.ts
- Converts entry files to TypeScript
- Configures Storybook to generate docs based on types
- Configures TypeScript on ESLint
- Configures Jest and ts-jest for TypeScript
- Fixes no-use-before-define problems on stories
- Ignores @typescript-eslint/no-unused-vars on mapFromWindowsTheme
- Fixes test failure on CSS check
@arturbien arturbien merged commit 659d102 into react95-io:beta Jul 24, 2022
@github-actions
Copy link

🎉 This PR is included in version 3.13.0-beta.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@WesSouza WesSouza deleted the typescript branch July 25, 2022 13:05
@github-actions
Copy link

🎉 This PR is included in version 4.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants