ami icon indicating copy to clipboard operation
ami copied to clipboard

Add Typescript support

Open NicolasRannou opened this issue 6 years ago • 27 comments

The objective of this PR is to help our migration process to TS. We will be able to use both TS and JS then just get rid of JS when all the code has been ported to TS.

  • Support TS and JS file (for smooth transition to type script)
  • Generate JS bundles as before
  • Generate definition files
  • Add a .tslint configuration file for editors to nicely pick up changes
  • Transpile every file to TS ?

NicolasRannou avatar Oct 02 '18 14:10 NicolasRannou

Do you want to get all code in typescript?

SerekKiri avatar Oct 02 '18 14:10 SerekKiri

Hey! I can try helping out with this! I don't have any experience with TS but I'm a quick learner. How did you envision the changeover? Update all/most JS files to TS or do them one at a time?

ShawnToubeau avatar Oct 02 '18 14:10 ShawnToubeau

I think that's too much work, but at least a couple of files and the bundles properly generated would be great, so we can continue the transition after the Hackoberfest :)

NicolasRannou avatar Oct 02 '18 14:10 NicolasRannou

I'm happy to split issue in multiple sub-issues if you think it makes sense so more people can work on it!

NicolasRannou avatar Oct 02 '18 14:10 NicolasRannou

Yea I think that would be awesome! You could maybe split it into file-by-file if that works?

ShawnToubeau avatar Oct 02 '18 14:10 ShawnToubeau

I think the first step is to update the webpack scripts then update one file at the time!

NicolasRannou avatar Oct 02 '18 14:10 NicolasRannou

Awesome! I can help with either or! About to go to class so I'll be busy for the next hour but afterwards I can start making the changeover!

ShawnToubeau avatar Oct 02 '18 14:10 ShawnToubeau

That being said if someone else wants to tackle the webpack scripts then by all means go ahead!

ShawnToubeau avatar Oct 02 '18 14:10 ShawnToubeau

@SerekKiri do you have experience with TS? If so I'd suggest you look into it if you are interested and after we can work on file by file conversion to TS.

Thoughts?

NicolasRannou avatar Oct 02 '18 14:10 NicolasRannou

Yes, i'm working on chatplug-mobile and chatplug so I think I'm not that bad. 💯

SerekKiri avatar Oct 02 '18 14:10 SerekKiri

AMI for me is amazing project I can help you with converting all files 😄

SerekKiri avatar Oct 02 '18 14:10 SerekKiri

@ShawnToubeau @SerekKiri so I'd suggest @SerekKiri improves the webpack configuration to also support TS / generate definitions then we can all work on file migration.

For me the challenge seems to be able to support both JS and TS in the same project!

NicolasRannou avatar Oct 02 '18 14:10 NicolasRannou

Ok, i can work only in the evening 👍 I'll be at 19-20 so if @ShawnToubeau have time now he can try 😄 or when i come back to home.

SerekKiri avatar Oct 02 '18 15:10 SerekKiri

@SerekKiri @NicolasRannou @ShawnToubeau : I have experience migrating from JavaScript to TypeScript in webpack at my day-job. I'm happy to help here.

AlexSwensen avatar Oct 02 '18 15:10 AlexSwensen

Can I suggest that the webpack configuration get split up into multiple files depending on the environment? (aka dev vs production?)

You can do this by creating a file like webpack.common.js and having everything each build shares in there, and then having a webpack.dev.js and webpack.production.js files that import that and extend the configuration. Then you can target the file you want based on the environment/script you are running.

This helps in a number of ways:

  1. much easier to maintain
  2. it's far more clear what is specific to a given build target.
  3. It will make implementing this issue easier if it is taken care of first.

The webpack docs give an example of this in its production tutorial.

AlexSwensen avatar Oct 02 '18 15:10 AlexSwensen

@AlexSwensen that's a great idea! Will read over the docs for that right now. @NicolasRannou is it difficult to integrate JS and TS into one project? Does it explicitly want one or the other?

ShawnToubeau avatar Oct 02 '18 16:10 ShawnToubeau

@AlexSwensen thanks for suggestions 😃. I was only working with ts, this is my first migration 😄 If you can and you want i will be very heppy when you will show us. 👍

SerekKiri avatar Oct 02 '18 18:10 SerekKiri

@SerekKiri @ShawnToubeau sure thing, I'll take a stab at this tonight once I'm off work.

In the mean time, i think i can simplify what I understand for the group.

TypeScript transpiles to JavaScript, and is an extension of the ES6/ESNext standard, so having javascript and typescript side-by-side in the same project is a natural progression.

From what I see in the current Webpack configuration, the rules for handling .js files are already taken care of. It should be a relatively simple matter of getting webpack to understand which loader to use for .ts files. (i would recommend starting with ts-loader, given it aligns with the official webpack docs.)

From that point, the migration from .js to .ts is iterative and can be done on a per-file basis as features are added and/or refactored.

I'll work on an example of this when i get home and put it up for review.

AlexSwensen avatar Oct 02 '18 19:10 AlexSwensen

Ok, thanks! Happy that I can learn something new 😄 👍

SerekKiri avatar Oct 02 '18 19:10 SerekKiri

@AlexSwensen just saw your PR, looks good to me!

I have a question though when I run for example yarn example geometries_slice it defaults to 0.0.0.0:8080 instead of localhost:8080. Is this a bug?

ShawnToubeau avatar Oct 03 '18 17:10 ShawnToubeau

@ShawnToubeau i replied in the PR. I think it should be good to go.

AlexSwensen avatar Oct 08 '18 04:10 AlexSwensen

I'll keep this one open to track overall progress of TS.

NicolasRannou avatar Oct 08 '18 08:10 NicolasRannou

'Models' and 'Parsers' should not be ported yet as there are some open PRs.

All the rest, included test should be.

Would be great if we can write more tests while porting the files :P

NicolasRannou avatar Oct 08 '18 09:10 NicolasRannou

Sweet, I can start helping convert some of the files over. @NicolasRannou what do you guys use to test? Don't have much experience writing tests but always willing to learn!

ShawnToubeau avatar Oct 09 '18 03:10 ShawnToubeau

@ShawnToubeau sorry for the late reply - we currently use karma with jasmine.

I think now I'd use karma with mocha + chai + sinon because it supports async testing better it seems.

Anyway, I'd suggest to convert code from /core and write tests (even dummy one, just to have basic structure running), and move from there!

Thanks

NicolasRannou avatar Oct 15 '18 09:10 NicolasRannou

No worries!! I can try converting some of the files later today/over the next few days. Will keep you updated! 😃

ShawnToubeau avatar Oct 15 '18 13:10 ShawnToubeau

Hi there -- any update on converting this to ts? I'd love to see this on DefinitelyTyped

adamwdennis avatar Feb 04 '20 03:02 adamwdennis