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

Enable TypeScript support in this repo #1459

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

bradenmacdonald
Copy link
Contributor

As part of taking over maintainership, I want to be able to use TypeScript to improve the quality of the code in this MFE.

This PR is split into three commits:

  1. Turn on TypeScript, set up tsconfig.json and add types for i18n and the constants in src/constants.ts. Updates the CI to do type checking.
  2. Update the entire new-sidebars folder to use TypeScript, as an example of converting an entire "thing" to TypeScript
  3. Rename all messages.js to messages.ts since none of the "messages" files require any changes to work as TypeScript.

Private ref: MNG-4362

@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Sep 12, 2024
@openedx-webhooks
Copy link

Thanks for the pull request, @bradenmacdonald!

What's next?

Please work through the following steps to get your changes ready for engineering review:

🔘 Get product approval

If you haven't already, check this list to see if your contribution needs to go through the product review process.

  • If it does, you'll need to submit a product proposal for your contribution, and have it reviewed by the Product Working Group.
    • This process (including the steps you'll need to take) is documented here.
  • If it doesn't, simply proceed with the next step.

🔘 Provide context

To help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:

  • Dependencies

    This PR must be merged before / after / at the same time as ...

  • Blockers

    This PR is waiting for OEP-1234 to be accepted.

  • Timeline information

    This PR must be merged by XX date because ...

  • Partner information

    This is for a course on edx.org.

  • Supporting documentation
  • Relevant Open edX discussion forum threads

🔘 Get a green build

If one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green.

🔘 Let us know that your PR is ready for review:

Who will review my changes?

This repository is currently maintained by @openedx/committers-frontend-app-learning. Tag them in a comment and let them know that your changes are ready for review.

Where can I find more information?

If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources:

When can I expect my changes to be merged?

Our goal is to get community contributions seen and reviewed as efficiently as possible.

However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:

  • The size and impact of the changes that it introduces
  • The need for product review
  • Maintenance status of the parent repository

💡 As a result it may take up to several weeks or months to complete a review and merge your PR.

Copy link

codecov bot commented Sep 12, 2024

Codecov Report

Attention: Patch coverage is 90.00000% with 2 lines in your changes missing coverage. Please review.

Project coverage is 88.69%. Comparing base (860b3f9) to head (3c78960).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
...urseware/course/new-sidebar/common/SidebarBase.tsx 71.42% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1459      +/-   ##
==========================================
+ Coverage   88.51%   88.69%   +0.17%     
==========================================
  Files         310      312       +2     
  Lines        5347     5501     +154     
  Branches     1323     1365      +42     
==========================================
+ Hits         4733     4879     +146     
- Misses        597      605       +8     
  Partials       17       17              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@bradenmacdonald
Copy link
Contributor Author

@farhaanbukhsh another PR for you - no rush :)

@farhaanbukhsh
Copy link
Member

@bradenmacdonald this will take some time :)

@itsjeyd itsjeyd added core contributor PR author is a Core Contributor (who may or may not have write access to this repo). waiting for eng review PR is ready for review. Review and merge it, or suggest changes. labels Sep 20, 2024
Copy link
Member

@farhaanbukhsh farhaanbukhsh left a comment

Choose a reason for hiding this comment

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

@bradenmacdonald thanks for this PR I do have a doubt there are a bunch of JS files are we going to migrate them later?

Comment on lines 49 to +52
export const WIDGETS = {
DISCUSSIONS: 'DISCUSSIONS',
NOTIFICATIONS: 'NOTIFICATIONS',
};
} as const satisfies Readonly<{ [k: string]: string }>;
Copy link
Member

Choose a reason for hiding this comment

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

export const WIDGETS: Readonly<{ [k: string]: string }> = {
  DISCUSSIONS: 'DISCUSSIONS',
  NOTIFICATIONS: 'NOTIFICATIONS',
};

@bradenmacdonald I just experimented with this and I found this to be more precise, what do you say?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That seems less precise to me? If you do that, the type actually just becomes this, which is basically "any object" - not very useful:

Screenshot

Whereas using the satisfies operator, we get the exactly correct type as a constant:

Screenshot

@@ -65,6 +65,7 @@ const NotificationsWidget = () => {

// After three seconds, update notificationSeen (to hide red dot)
useEffect(() => {
// eslint-disable-next-line @typescript-eslint/no-implied-eval
Copy link
Member

@farhaanbukhsh farhaanbukhsh Oct 3, 2024

Choose a reason for hiding this comment

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

Are we running the linter for TS and TSX? I can't find the command being updated and changes in eslintrc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops, you are right. Fixed with dc39854. Changing .eslintrc shouldn't be needed since it inherits from frontend-build which already configures eslint to support typescript.

@bradenmacdonald
Copy link
Contributor Author

@farhaanbukhsh Yeah, we can slowly convert the JS to TS. It's too complex to do it all at once. But once this PR is merged, we can convert things as we go, and all new stuff can use TS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core contributor PR author is a Core Contributor (who may or may not have write access to this repo). open-source-contribution PR author is not from Axim or 2U waiting for eng review PR is ready for review. Review and merge it, or suggest changes.
Projects
Status: Ready for Review
Development

Successfully merging this pull request may close these issues.

4 participants