web icon indicating copy to clipboard operation
web copied to clipboard

Upgrade to TypeScript 5

Open ArttuOll opened this issue 3 years ago • 15 comments

ts-patch (the successor of ttypescript) has released a beta which adds support for TypeScript 5 and asked consumers to test it. In this branch, I've confirmed that this library works with the new version of ts-patch.

I've:

  • Replaced ttypescript with ts-patch (since ttypescript is not being developed anymore).
  • Fixed a type-narrowing-related bug in useEventListener that appeared with TypeScript 5.

This can be merged later, when the release version of ts-patch is available. I'll also format the commit messages then.

ArttuOll avatar Apr 10 '23 12:04 ArttuOll

There is one thing i dont like about ts-patch - in some kind ts-patch breaks typecript itself - it is not something built around typescript like ttypescript, it injects into TS itself.

xobotyi avatar Apr 11 '23 07:04 xobotyi

Otherwise - we're not in hurry here. TS 5 broken lots of things out there, i wast even able to switch any of projects at work, bcause of incompatibility.

xobotyi avatar Apr 11 '23 07:04 xobotyi

There is one thing i dont like about ts-patch - in some kind ts-patch breaks typecript itself - it is not something built around typescript like ttypescript, it injects into TS itself.

The question I would ask now is: could we get rid of the dependency altogether? Is ttypescript really necessary?

ArttuOll avatar Apr 11 '23 07:04 ArttuOll

Weeelp, with some tinkering around linting (that will enforce .js extension within imports) and TS configs - it is possible to get rid of plugins now. It was not, at the moment ttsc been introduced to our repos.

xobotyi avatar Apr 11 '23 07:04 xobotyi

And maybe you're right. Better move will be to get rid of plugins alltogether. It will require changing all imports and, i think, switch module resolution to ESNext (or maybe NodeNext)

xobotyi avatar Apr 11 '23 07:04 xobotyi

And maybe you're right. Better move will be to get rid of plugins alltogether. It will require changing all imports and, i think, switch module resolution to ESNext (or maybe NodeNext)

Sounds good. I'm totally up for committing time to this.

ArttuOll avatar Apr 11 '23 07:04 ArttuOll

I upgraded TypeScript, removed ttypescript, replaced ttsc with tsc in build scripts, changed module resolution to NodeNext and everything appears to work now.

ArttuOll avatar Apr 15 '23 16:04 ArttuOll

Codecov Report

Merging #1194 (9af3992) into master (284e499) will decrease coverage by 0.10%. The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master    #1194      +/-   ##
==========================================
- Coverage   98.49%   98.40%   -0.10%     
==========================================
  Files          62       62              
  Lines        1064     1064              
  Branches      179      179              
==========================================
- Hits         1048     1047       -1     
- Misses          2        3       +1     
  Partials       14       14              
Impacted Files Coverage Δ
src/useEventListener/index.ts 100.00% <100.00%> (ø)

... and 1 file with indirect coverage changes

:mega: We’re building smart automated test selection to slash your CI/CD build times. Learn more

codecov[bot] avatar Apr 15 '23 16:04 codecov[bot]

🤔 does it generate files that have .js imports? im pretty much surprised that it dont require.js extension in imports

xobotyi avatar Apr 19 '23 17:04 xobotyi

Well that was the point of plugin We have to enforce extensions otherwise esm won't work.

xobotyi avatar Apr 20 '23 15:04 xobotyi

The imports and requires of the generated files don't have any extensions (deleted the previous comment, because I built the wrong branch).

ArttuOll avatar Apr 20 '23 15:04 ArttuOll

Interesting. I guess we'll have to go with ts-patch then? ttypescript and such won't work with TypeScript 5.

ArttuOll avatar Apr 20 '23 15:04 ArttuOll

Nope Just enforce it on linter level.

xobotyi avatar Apr 20 '23 15:04 xobotyi

maybe we have to consider finally switch to "type": "module". As for me we finally migrated all our production services to native esm.

xobotyi avatar May 02 '23 07:05 xobotyi

so here's the plan.

  1. process current PR's
  2. migrate to new hooks testing library (@testing-library/react-hooks -> @testing-library/react)
  3. migrate to type: module
  4. migrate from storybook to docosurus (supposedly, not sure yet if docosaurus is viable with our directorues structure)

xobotyi avatar May 14 '23 08:05 xobotyi