-
Notifications
You must be signed in to change notification settings - Fork 65
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
[BD-46] feat: add typescript support #1267
Conversation
✅ Deploy Preview for paragon-openedx ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify site settings. |
Thanks for the pull request, @viktorrusakov! When this pull request is ready, tag your edX technical lead. |
'error', | ||
'warning', | ||
]; | ||
const STYLE_VARIANTS = ['primary', 'success', 'error', 'warning'] as const; |
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.
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,
...
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 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.
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.
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
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 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.
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.
Looking good! Left a couple clarifying questions.
'error', | ||
'warning', | ||
]; | ||
const STYLE_VARIANTS = ['primary', 'success', 'error', 'warning'] as const; |
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 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" | ||
] | ||
} |
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.
nit: newline
src/withDeprecatedProps.tsx
Outdated
</WrappedComponent> | ||
); | ||
} | ||
} | ||
|
||
// @ts-ignore |
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.
[curious] why does this need to be ts-ignore'd
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.
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})`;
8132b7e
to
c2c4f11
Compare
c2c4f11
to
b21ad01
Compare
Codecov Report
@@ 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
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
20ea335
to
d002219
Compare
# --copy-files will bring in everything else that wasn't processed by babel. Remove what we don't want. | ||
rm -rf dist/**/*.test.jsx |
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 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
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 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 😬
"type-check": "tsc --noEmit", | ||
"type-check:watch": "npm run type-check -- --watch", | ||
"build-types": "tsc --emitDeclarationOnly" |
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.
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 😄
d002219
to
5e46b37
Compare
@adamstankiewicz rebased, should be good to go! |
@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. |
🎉 This PR is included in version 20.8.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
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
wittjeff
andadamstankiewicz
as reviewers on this PR.Post-merge Checklist