Skip to content

TypeScript Migration #43778

Closed
Closed

Description

@ShaunSHamilton

Co-ordination

As discussed in the last contributors meeting we're looking to migrate our client to TypeScript.

No files will be assigned

PRs will be prioritised by quality, then by date opened

Guidelines

Take a look at the Codebase Best Practices - kebab-case file names

Small is beautiful

If a file can be migrated on its own, that's perfect. That makes the PR incredibly easy to review and minimises the chance we break anything.

PropTypes can go

None of the components in the client directories are intended to be consumed by JavaScript components - eventually everything will be tsx. With that in mind static type checking should be enough.

React Guidelines

So, we're all on the same page: https://github.com/typescript-cheatsheets/react#readme has some useful advice. Mostly the linters will warn us, but this is definitely worth a look.

un-typed packages

If the package does not come with types attached, then please npm i the definitions (if they exist) from DefinitelyTyped. Usually they're just published as @types/name-of-package.

Do Not Ignore Linting, Unless Absolutely Necessary

We hope to leverage the type-safety that comes with TypeScript. So, do not ignore the compiler's warnings/errors. If you are stuck, feel free to reach out for help.

Keeping Git History

Sometimes changing the file from <filename>.js -> <filename>.tsx? causes the original file to be deleted, and a new one created, and other times the filename just changes - in terms of Git. Ideally, we want the file history to be preserved.

The best bet at achieving this is to:

  1. Rename the file
  2. Commit with the flag --no-verify to prevent husky from complaining about the errors
  3. Refactor to TS for migration, in a separate commit.

Note: Editors like VSCode are still likely to show you the file has been deleted and a new one created. If you use the CLI to git add ., then VSCode will show the file as renamed in stage

Tests are running

We will not be merging any PRs with failing tests.

Files that should not be migrated (yet)

  • gatsby-node.js
  • gatsby-config.js and related
  • redux/*

To finish migrating the client, we would need additional tooling to handle gatsby-config, gatsby-node and files they import. This could either be an extra tsc compilation step or potentially via ts-node. However, I'm not sure if ts-node would integrate nicely with gatsby develop or gatsby build, so the compilation approach is probably easier.

Before going ahead with this, we should profile gatsby develop and gatsby build to make sure that the time to develop and build the site do not increase too much.

More guidelines may get added

As we do this, chances are we'll revise the approach. Any thoughts/comments/critiques are welcome, but I wanted to keep this straightforward for now.

List of Files To Migrate

  • /client/src/templates/Challenges/utils/worker-executor.js
  • /client/src/templates/Challenges/utils/worker-executor.test.js
  • /client/src/templates/Challenges/rechallenge/transformers.js
  • /client/src/__mocks__/react-i18next.js

Activity

  1. added
    help wanted
    platform: learn
    on Oct 8, 2021
  2. pinned this issue on Oct 8, 2021
  3. RobertoMSousa commented on Oct 8, 2021

    @RobertoMSousa
    Contributor

    @ShaunSHamilton I can help. If there's anything available 😉

  4. majestic-owl448 commented on Oct 8, 2021

    @majestic-owl448
    Contributor

    @RobertoMSousa now it's back to usual, without assignments, as it says in the first post. PRs will be prioritized by quality and date opened.

    In short, go for it with what you feel like with the non assigned files

  5. RobertoMSousa commented on Oct 8, 2021

    @RobertoMSousa
    Contributor

    Should we keep the migration by component or can we merge them on a single PR?
    It's a little spam create 2 PR with so little changes 😅
    #43783
    #43784

    But on the other hand, it's easier to review and keep track of possible bugs.

  6. ojeytonwilliams commented on Oct 8, 2021

    @ojeytonwilliams
    Contributor

    @RobertoMSousa Don't worry, it's not spam. Small PRs, like the ones you've submitted, are great.

  7. sitek94 commented on Oct 8, 2021

    @sitek94
    Contributor

    Hello 👋

    I've just opened a small PR with migration of remaining parts of the Landing component.

    If I find some more time over the weekend, and there will still be something to do, I'll try to help :)

  8. Pranav2612000 commented on Oct 10, 2021

    @Pranav2612000
    Contributor

    I'll also like to help with this. I can see a couple of PRs already. How do I know which unassigned files are still pending?

  9. Nirajn2311 commented on Oct 10, 2021

    @Nirajn2311
    Member

    @Pranav2612000 You can use this site(https://tools.freecodecamp.org) to check if an unassigned file has an open PR or not.

  10. Ethan-Edmond commented on Oct 12, 2021

    @Ethan-Edmond
    Contributor

    Hey, I just tried working on throwers.js and I noticed that it's not being imported anywhere. Are there plans for this file, or should it be deleted?

  11. AbdelilahRami commented on Oct 13, 2021

    @AbdelilahRami

    I will work on : /client/src/components/layouts/Default.js

  12. ojeytonwilliams commented on Oct 13, 2021

    @ojeytonwilliams
    Contributor

    Hey, I just tried working on throwers.js and I noticed that it's not being imported anywhere. Are there plans for this file, or should it be deleted?

    Hi @Ethan-Edmond. Yep, that looks to be obsolete code that can be deleted.

  13. aprilsourz commented on Oct 13, 2021

    @aprilsourz

    Hi! I'll work on these files

     /client/src/components/Map/Map.test.js
     /client/src/components/Intro/Intro.test.js
     /client/src/components/Intro/index.js
    
  14. mendaomn commented on Oct 14, 2021

    @mendaomn

    Hey, would love to take on /client/src/templates/Challenges/components/Test-Suite.js

  15. 43 remaining items

  16. a2937 commented on Aug 16, 2022

    @a2937
    Member

    Thank you very much. I didn't have prior experience using Web Workers before in JavaScript. Also now I have another slight hiccup. What exactly is eventify? I believe it's some sort of EventListener/Dispatcher but don't know the exact class name at the minute. And secondly I assume the done method right here

    _processQueue() {
    while (this._workersInUse < this._maxWorkers && this._taskQueue.length) {
    const task = this._taskQueue.shift();
    const handleTaskEnd = this._handleTaskEnd(task);
    task._execute(this._getWorker).done.then(handleTaskEnd, handleTaskEnd);
    this._workersInUse++;
    }
    }

    refers to the promise method defined here.

    task.done = new Promise((resolve, reject) => {

    Edit: I am also of the assumption now Tasks are from the same codebase as Web Workers but can't find any exact matches so far.

  17. Karorule commented on Sep 13, 2022

    @Karorule
  18. Karorule commented on Sep 13, 2022

    @Karorule
  19. ShaunSHamilton commented on Sep 24, 2022

    @ShaunSHamilton
    MemberAuthor

    @wojtekxtx Fun fact: If you read through, this was started on the 26th of May 2021.

    We welcome contribution from yourself. Also I would be interested in seeing an example of these tools.

  20. bradtaniguchi commented on Sep 25, 2022

    @bradtaniguchi

    I do not touch projects that are of questionable reputation

    ???

    Then why comment on this issue?🤔

  21. bradtaniguchi commented on Sep 25, 2022

    @bradtaniguchi

    @bradtaniguchi By touching I meant: developing code for this wannabe serious project. Nothing did I say about comments.

    Do you have any examples of where freeCodeCamp is a "wannabe serious" project in regards to the current TypeScript migration?

    I think having some clear code examples and advice on how to improve the TS migration wouldn't be too difficult for a pro such as yourself :)

  22. bradtaniguchi commented on Sep 25, 2022

    @bradtaniguchi

    its members need close to a year just to finish WPM-type task.

    I believe all tasks have been accomplished by unpaid volunteers that devote their time and expertise. The fact it's getting done at all is really awesome IMO. It's not exactly easy to migrate over to a large and expansive codebase such as freeCodeCamp to TS, when there's "multiple hands in the pot" all at once. Getting it done in any form or fashion will be a big win.

    I will reiterate: Im NOT going to show where code could be improved as Im not going to devote my time to project(s) of such low quality as freecodecamp.

    I thought it was just code contributions you don't have time/effort for? Any feedback or "code reviews" would be appreciated. Even a basic code critique would be useful, especially if the product is of such "low quality". Such efforts shouldn't take any more time it takes than to respond, however such a response would positively help the platform moving forward.

    Otherwise anyone can see the date this issue has been created, but very few actually contribute to the platform.

  23. locked as off topic and limited conversation to collaborators on Sep 26, 2022
  24. Sboonny commented on Nov 17, 2022

    @Sboonny
    Member

    While talking to Oliver about nav-link.tsx theme and how the connect function in it expect Action<any> result.

    Here is a picture for clearance.

    image

    So I am wondering if it's okay to add action.js to the list of migration and for me to add generic types to it, or is there a reason for it to not be in the list currently?


    Edit: nvm, I have misread part of the section redux/* files aren't to be migrated yet

  25. unpinned this issue on Feb 5, 2023
  26. Sembauke commented on Jan 10, 2024

    @Sembauke
    Member

    I am going ahead and close this as completed. These workers and transformers are not worth migrated due to the TypeScript gymnastics.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedplatform: learn

    Type

    No type

    Projects

    • Status
      Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions