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

[BD-46] feat: add typescript support #1267

Merged

Conversation

viktorrusakov
Copy link
Contributor

Description

Add TypeScript support

Deploy Preview

Include a direct link to your changes in this PR's deploy preview here (e.g., a specific component page).

Merge Checklist

  • If your update includes visual changes, have they been reviewed by a designer? Send them a link to the Netlify deploy preview, if applicable.
  • Does your change adhere to the documented style conventions?
  • Do any prop types have missing descriptions in the Props API tables in the documentation site (check deploy preview)?
  • Were your changes tested using all available themes (see theme switcher in the header of the deploy preview, under the "Settings" icon)?
  • Is there adequate test coverage for your changes?
  • Consider whether this change needs to reviewed/QA'ed for accessibility (a11y). If so, please add wittjeff and adamstankiewicz as reviewers on this PR.

Post-merge Checklist

  • Verify your changes were released to NPM at the expected version.
  • If you'd like, share your contribution in #show-and-tell.
  • 🎉 🙌 Celebrate! Thanks for your contribution.

@netlify
Copy link

netlify bot commented May 5, 2022

Deploy Preview for paragon-openedx ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 5e46b37
🔍 Latest deploy log https://app.netlify.com/sites/paragon-openedx/deploys/62ebc022cab391000872fc42
😎 Deploy Preview https://deploy-preview-1267--paragon-openedx.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@openedx-webhooks
Copy link

openedx-webhooks commented May 5, 2022

Thanks for the pull request, @viktorrusakov!

When this pull request is ready, tag your edX technical lead.

@openedx-webhooks openedx-webhooks added blended PR is managed through 2U's blended developmnt program needs triage labels May 5, 2022
@viktorrusakov viktorrusakov marked this pull request as draft May 5, 2022 13:15
'error',
'warning',
];
const STYLE_VARIANTS = ['primary', 'success', 'error', 'warning'] as const;
Copy link
Contributor

@monteri monteri May 11, 2022

Choose a reason for hiding this comment

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

Is it good idea to change to enum?

enum STYLE_VARIANTS {
  PRIMARY = 'primary',
  SUCCESS = 'success',
  ...
}

and then in the interface we can

...
variant?: STYLE_VARIANTS,
...

Copy link
Member

Choose a reason for hiding this comment

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

I agree, an enum is cleaner for the types, but STYLE_VARIANTS is still used in the prop types. That said, once a component has types for the props as Bubble now does, the PropType definitions become less meaningful. They'd really only used for the purpose of forming the "Props API" tables on the component pages in the documentation site, I believe.

Will we need to keep both types and prop types moving forward or I wonder if we should do some technical discovery around migrating away from prop types while keeping the same functionality with generating the props api tables.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I didn't use enum because it conflicts with propTypes, I didn't find a good way to reuse it in propTypes definition, so that it correctly displays in Props API table...

I think we will need to keep propTypes even when we move to TypeScript types, because they have different purpose - TypeScript types work only during compile type while propTypes during runtime, this means if we remove propTypes and consumers pass some variant that is not in STYLE_VARIANTS they will not get a warning that this prop is invalid. I guess they would if they have TypeScript setup inn their projects... but I believe most MFEs (if not all of them) do not use TypeScript

Copy link
Member

Choose a reason for hiding this comment

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

I guess they would if they have TypeScript setup inn their projects... but I believe most MFEs (if not all of them) do not use TypeScript

This is correct. The TypeScript in this PR is the first TypeScript introduced in the Open edX platform, AFAIK. It's a great callout for build time vs. runtime validation in TypeScript and propTypes; I agree it makes sense we should probably use both for the time being, until we learn otherwise.

Copy link
Member

@adamstankiewicz adamstankiewicz 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! Left a couple clarifying questions.

'error',
'warning',
];
const STYLE_VARIANTS = ['primary', 'success', 'error', 'warning'] as const;
Copy link
Member

Choose a reason for hiding this comment

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

I agree, an enum is cleaner for the types, but STYLE_VARIANTS is still used in the prop types. That said, once a component has types for the props as Bubble now does, the PropType definitions become less meaningful. They'd really only used for the purpose of forming the "Props API" tables on the component pages in the documentation site, I believe.

Will we need to keep both types and prop types moving forward or I wonder if we should do some technical discovery around migrating away from prop types while keeping the same functionality with generating the props api tables.

tsconfig.json Outdated
"include": [
"src"
]
}
Copy link
Member

Choose a reason for hiding this comment

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

nit: newline

</WrappedComponent>
);
}
}

// @ts-ignore
Copy link
Member

Choose a reason for hiding this comment

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

[curious] why does this need to be ts-ignore'd

Copy link
Contributor Author

@viktorrusakov viktorrusakov Jul 11, 2022

Choose a reason for hiding this comment

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

TypeScript complained that displayName property does not exist in the component, so you can't assign it.

I force-pushed, so you can't see anymore, but ts-ignore complained about line

WithDeprecatedProps.displayName = `withDeprecatedProps(${componentName})`;

@adamstankiewicz adamstankiewicz mentioned this pull request May 13, 2022
27 tasks
@viktorrusakov viktorrusakov force-pushed the rusakov/add-typescript-support branch 2 times, most recently from 8132b7e to c2c4f11 Compare May 18, 2022 13:48
@adamstankiewicz adamstankiewicz linked an issue May 27, 2022 that may be closed by this pull request
@viktorrusakov viktorrusakov force-pushed the rusakov/add-typescript-support branch from c2c4f11 to b21ad01 Compare July 10, 2022 08:11
@codecov
Copy link

codecov bot commented Jul 10, 2022

Codecov Report

Merging #1267 (5e46b37) into master (a1b7bf9) will increase coverage by 0.02%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master    #1267      +/-   ##
==========================================
+ Coverage   91.42%   91.44%   +0.02%     
==========================================
  Files         205      205              
  Lines        3474     3484      +10     
  Branches      817      818       +1     
==========================================
+ Hits         3176     3186      +10     
+ Misses        284      283       -1     
- Partials       14       15       +1     
Impacted Files Coverage Δ
src/Button/deprecated/index.jsx 92.00% <ø> (ø)
src/CheckBox/index.jsx 90.00% <ø> (ø)
src/Chip/index.jsx 90.90% <ø> (ø)
...rc/DataTable/filters/MultiSelectDropdownFilter.jsx 100.00% <ø> (ø)
src/Dropdown/deprecated/index.jsx 94.84% <ø> (ø)
src/Hyperlink/index.jsx 73.91% <ø> (ø)
src/Icon/index.jsx 100.00% <ø> (ø)
src/InputSelect/index.jsx 12.50% <ø> (ø)
src/InputText/index.jsx 88.88% <ø> (ø)
src/MailtoLink/index.jsx 100.00% <ø> (ø)
... and 9 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@viktorrusakov viktorrusakov marked this pull request as ready for review July 11, 2022 05:22
@viktorrusakov viktorrusakov changed the title DRAFT: [BD-46] feat: add typescript support [BD-46] feat: add typescript support Jul 11, 2022
@viktorrusakov viktorrusakov force-pushed the rusakov/add-typescript-support branch 2 times, most recently from 20ea335 to d002219 Compare July 11, 2022 09:28
# --copy-files will bring in everything else that wasn't processed by babel. Remove what we don't want.
rm -rf dist/**/*.test.jsx
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This didn't work as expected I think, build still had tests files inside tests folder (e.g. Datatable/tests/ is still in the dist directory with tests files in there), I think it deleted files only one level deep not going into all subdirectories.

Rewrote this to make sure we delete all tests and md files from the build

Copy link
Member

@adamstankiewicz adamstankiewicz left a comment

Choose a reason for hiding this comment

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

This PR looks good to me! 🚀 I added just one comment about a potential follow-on ADR/documentation task for TypeScript, but let's get this PR in first.

Likely due to the recently merged security vulnerability package upgrades PR, there's bound to be quite a few merge conflicts on this PR unfortunately, though 😬

Comment on lines +45 to +47
"type-check": "tsc --noEmit",
"type-check:watch": "npm run type-check -- --watch",
"build-types": "tsc --emitDeclarationOnly"
Copy link
Member

Choose a reason for hiding this comment

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

It might be a good idea to add documentation about what these commands do and when/why we should use them somewhere in the repo. It very well could be the starting documentation for how to work with TypeScript for all of Open edX.

Related, did we write an ADR (Architectural Decision Record) about TypeScript? If not, that's probably something we should do. Is this something you might want to take on? Let's treat that as a task separate from this PR, though 😄

@viktorrusakov
Copy link
Contributor Author

@adamstankiewicz rebased, should be good to go!

@adamstankiewicz adamstankiewicz merged commit a31591e into openedx:master Aug 5, 2022
@openedx-webhooks
Copy link

@viktorrusakov 🎉 Your pull request was merged! Please take a moment to answer a two question survey so we can improve your experience in the future.

edx-semantic-release pushed a commit that referenced this pull request Aug 5, 2022
# [20.8.0](v20.7.0...v20.8.0) (2022-08-05)

### Bug Fixes

* fixed Card import ([#1522](#1522)) ([ebcf090](ebcf090))

### Features

* add typescript support ([#1267](#1267)) ([a31591e](a31591e))
@edx-semantic-release
Copy link
Contributor

🎉 This PR is included in version 20.8.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
Labels
blended PR is managed through 2U's blended developmnt program raccoon-gang released
Projects
No open projects
Archived in project
Development

Successfully merging this pull request may close these issues.

5 participants