mockdeep / typewiz

Automatically discover and add missing types in your TypeScript code
https://medium.com/@urish/manual-typing-is-no-fun-introducing-typewiz-58e3e8813f4c
1.1k stars 46 forks source link

This typings #40

Closed zoehneto closed 6 years ago

zoehneto commented 6 years ago

Optionally applies this types to functions. Fixes #33 .

coveralls commented 6 years ago

Coverage Status

Coverage increased (+0.3%) to 85.649% when pulling 641f3e5fbefaae8e8529d9c3edbf3a7498385f7b on zoehneto:this-typings into 7d9f39afb523d363496f56762cf9bafdbc562465 on urish:master.

urish commented 6 years ago

Lovely, thank you very much! I left a few comments, but overall looks really nice :)

zoehneto commented 6 years ago

Thanks for the quick review, I addressed your comments in the latest commit.

urish commented 6 years ago

Awesome, thanks!

Just out of curiosity - have you used TypeWiz on any of your projects?

zoehneto commented 6 years ago

What is not yet covered by this PR (and was also not covered in #27) is how to roll out these changes to typewiz-node and typewiz-webpack. I personally don't use either since I bundle with rollup and then test the bundle but this should be considered going forward.

zoehneto commented 6 years ago

Just saw your comment, I have experimentally added typewiz to rtf.js where I use a custom script for instrumentation.

urish commented 6 years ago

Very interesting - so in this case, you are basically writing an instrumented copy of your source code to the build directory, and then the tests run using the instrumented source code, right?

I couldn't find where you told the bundle / test steps to read the source files from the build directory though, can you please point me?

zoehneto commented 6 years ago

It works as follows:

  1. typewiz-instrument.js instruments the files using the typewiz api (the key here is to pass the original filenames in the source directory to the instrumenter), compiles the individual files using the typescript api and then writes the files to the build directory.
  2. Then npm run bundle is invoked which creates three UMD / ES5 bundles in the dist directory based on the instrumented code from build
  3. The test suite is started using npm run test which runs the script test/test-rtfjs.js (this script executes a test for every directory under test/test-files and applies the collected types after all tests are finished). To execute the individual tests test/utils.js is used which converts rtf files to html. Since rtf.js requires a browser to run (because of some of the libraries it's built on) the actual test is executed using JSDOM which loads the scripts from dist (line 30 - 32) and has to be passed $_$twiz (line 105).
urish commented 6 years ago

Got it, thanks!

I'm currently helping migrate immer to TS using typewiz, and they are also using rollup for their build. In their case, I used rollup-plugin-typescript2. In your build, you are running TypeScript as a separate compile step. Is there any reason for preferring running TypeScript separately and not as part of rollup?

zoehneto commented 6 years ago

In rtf.js we build three separate bundles (for rtf.js, emf.js and wmf.js) but building rtf.js requires building the other two with tsc in the same step (because of some import tricks it uses) so if it used the rollup plugin emf.js and wmf.js would be built twice.

urish commented 6 years ago

And how useful have you found TypeWiz so far for rtf.js?

zoehneto commented 6 years ago

Sadly I found your blog post too late. A month ago it was just three plain ES5 files with around 9000 lines of code and then I did the entire conversion by hand and added all the typings :(

urish commented 6 years ago

I hear you... I did the same with several projects before coming up with TypeWiz. But the future will be brighter :)

urish commented 6 years ago

Released as part of 0.7.0