brain.js icon indicating copy to clipboard operation
brain.js copied to clipboard

Migrate to TypeScript

Open mubaidr opened this issue 6 years ago • 137 comments

We plan to gradually migrate brain.js to TypeScript, code base is pretty large, so we would love your help! 💪

How to contribute?

  • Convert a file from .js to .ts
  • Add types, fix all type errors.
  • Submit a PR! 🎉

Here you can find a guide on how to contribute.

Want to convert something, let us know in the comment and go ahead! 😎

To avoid duplicate work please comment on which part you want to work on (as long as nobody else is working on it) so we can mark it as taken.

Reach out to us! Feel free to reach if you have questions or need help getting started. You can leave comments here or you can tag me in your PR if you need any help or you're not sure about something!

You can also get in touch on our Gitter & Slack.

Happy Coding! 🤟


UPDATE:

Wohoooo!!! 🎉

All files inside src directory are migrated to typescript. (Except few ones which are already taken up and being worked on), though we are still looking on improvements to types in these files and removing any types from the source. You are welcome to contribute. 😊

__tests__ directory has still some files left that needs migration to typescript, so feel free to pick em up! 🍭


UPDATE

For anyone looking to contribute, here is the list of files that still needs typescript migration:

https://github.com/BrainJS/brain.js/search?l=javascript&p=1

mubaidr avatar May 17 '20 20:05 mubaidr

I'd like to start working on this, I have some experience with Ts, can you tell me which module is up for grabs?

yashshah1 avatar Jul 25 '20 11:07 yashshah1

@yashshah1 You are welcome to contribute, please pick any module or portion for conversion and mention it here, so I can mark it in-progress (to avoid any duplication effort).

mubaidr avatar Jul 25 '20 11:07 mubaidr

I'd like to work on this too, any recommendations on where to start?

nabeelvalley avatar Aug 05 '20 15:08 nabeelvalley

@nabeelvalley here is the short guide, super simple to start. Please pick any module or portion for conversion and mention it here, so I can mark it in-progress (to avoid any duplication effort).

Here you can find a guide on how to contribute.

mubaidr avatar Aug 05 '20 20:08 mubaidr

@mubaidr I'm working from the utilities up, to avoid having untyped dependencies

The tests seem to be failing when I convert the file to JS because it looks like Jest is running against the TS files instead of the compiled JS - has the TS Compile been configured?

Looks like the tests are also currently failing:

Test Suites: 1 failed, 5 passed, 6 of 64 total
Tests:       9 failed, 114 passed, 123 total
Snapshots:   0 total
Time:        206.723 s

It appears that the soft-max tests are receiving a Float32Array instead of a plain array - should I look where the Float32 is coming from or should I update the unit tests to expect a Floar32Array instead?

The data returned looks exactly the same, it's just that the object types are different so the deep equality is failing:

Example for one of the tests below:

  ● SoftMax › .compare2D › can run on a simple matrix

    assert.deepEqual(received, expected)

    Expected value to deeply equal to:
      [[-0, 2], [3, 4]]
    Received:
      [[-0, 2], [3, 4]]

    Difference:

    - Expected
    + Received

      Array [
    -   Array [
    +   Float32Array [
          -0,
          2,
        ],
    -   Array [
    +   Float32Array [
          3,
          4,
        ],
      ]

nabeelvalley avatar Aug 06 '20 15:08 nabeelvalley

Yes, you can update test to expect Float32Array.

In the mean-time some tests might still fail, because they have not yet been updated recently. You can can continue working and make sure build process is successful and conversion does not cause increase in no. of failed tests.

mubaidr avatar Aug 09 '20 12:08 mubaidr

Hi! I want to help. If I convert one file, do I need to convert related files too or something? Or just a single file?

harshkhandeparkar avatar Aug 28 '20 16:08 harshkhandeparkar

You don't need to updated all the related files, just go file by file and make sure build is successful.

mubaidr avatar Aug 28 '20 17:08 mubaidr

Utilities is taken, isnt it?

harshkhandeparkar avatar Aug 28 '20 17:08 harshkhandeparkar

Activation functions seem like a good place to start, may I work on it?

harshkhandeparkar avatar Aug 28 '20 17:08 harshkhandeparkar

Utilities is taken, isnt it?

Hi @HarshKhandeparkar, I haven't had a chance to work on this you're welcome to take utilities if you want, just note that needs to be updated above

nabeelvalley avatar Aug 28 '20 17:08 nabeelvalley

Np @nabeelvalley. I think I'll work on activation functions :)

harshkhandeparkar avatar Aug 28 '20 17:08 harshkhandeparkar

@nabeelvalley I think I managed to fix the jest error you were facing in #582. You may copy paste my changes to jest.config.json or wait for the PR to be merged :)

harshkhandeparkar avatar Aug 29 '20 03:08 harshkhandeparkar

estimator/ has a single file. Looks like a nice :dart:.

harshkhandeparkar avatar Aug 29 '20 07:08 harshkhandeparkar

I think I'll snipe some of the utilities next, if you don't mind @nabeelvalley.

harshkhandeparkar avatar Aug 30 '20 19:08 harshkhandeparkar

You would have probably started in alphabetical order(I am assuming), so I am going to start from the bottom.

harshkhandeparkar avatar Aug 30 '20 19:08 harshkhandeparkar

Going to snipe utilities/values* tonight :)

harshkhandeparkar avatar Sep 01 '20 16:09 harshkhandeparkar

Huzzah!

robertleeplummerjr avatar Sep 01 '20 17:09 robertleeplummerjr

Build systems seems to be broken, I am looking into this issue. 🧯

mubaidr avatar Sep 01 '20 18:09 mubaidr

Can I continue or should I wait?

harshkhandeparkar avatar Sep 01 '20 18:09 harshkhandeparkar