question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeScript 4.7 compat

See original GitHub issue

Prerequisites

Environment check

  • I’m using the latest msw version
  • I’m using Node.js version 14 or higher

Node.js version

irrelevant, this is a type-only issue

Reproduction repository

see CI builds below

Reproduction steps

see this CI build

Current behavior

Right now, msw as a dependency causes three errors with TypeScript 4.7:

Error: ../../node_modules/msw/lib/types/sharedOptions.d.ts(23,83): error TS2344: Type 'ResponseType' does not satisfy the constraint 'Record<string | symbol, any>'.
Error: ../../node_modules/msw/node_modules/type-fest/ts41/get.d.ts(95,37): error TS2344: Type 'BaseType' does not satisfy the constraint 'Record<string | number, any>'.
Error: ../../node_modules/msw/node_modules/type-fest/ts41/get.d.ts(96,19): error TS2344: Type 'BaseType' does not satisfy the constraint 'Record<string | number, any>'.
Error: Process completed with exit code 2.

Two of those originate from the dependency type-fest, which in the currently used major version 1 does not seem to support TS 4.7. Since type-fest does not have multiple major-version branches and already has an open issue for a v3, I would assume they are not going to backport any fixes (although I might be wrong).

Updating the dependency to major version 2 seems to fix that issue. That would drop type-fest support for TS<4.2 though - I guess it’s either support for future TS versions or old versions at that point.

The other error seems to be resolved by changing

-export declare type LifeCycleEventEmitter<ResponseType> = Pick<StrictEventEmitter<ResponseType>, 'on' | 'removeListener' | 'removeAllListeners'>;
+export declare type LifeCycleEventEmitter<ResponseType extends Record<string | symbol, any>> = Pick<StrictEventEmitter<ResponseType>, 'on' | 'removeListener' | 'removeAllListeners'>;

I can open a PR for that if desired.

Expected behavior

No type errors, even with skipLibChecks: false

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:2
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
kettanaitocommented, Apr 18, 2022

Hey, @phryneas. Thanks for raising this.

We don’t have official support for TS >= 4.4 but if your suggestion is compatible with 4.3 which we support now, I’d love to have this merged. In any case, opening a pull request would be useful. Thank you!

1reaction
kettanaitocommented, May 28, 2022

With #1256, the library should be compatible with TypeScript 4.7. Could you please test it out and report any issues?

I don’t think we have to cover the proposed changes in the types above.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Documentation - TypeScript 4.7
TypeScript 4.7 Release Notes. ... grabs the type of the first element as S . Then it checks if S is compatible with...
Read more >
Announcing TypeScript 4.7 - Microsoft Developer Blogs
Today we're excited to announce the availability of TypeScript 4.7! If you're not yet familiar with TypeScript, it's a language that builds ...
Read more >
What's new in TypeScript 4.7 - LogRocket Blog
This update specifically revolves around new features for type inference, narrowing analysis, ES module integration, instantiation expressions, ...
Read more >
TypeScript 4.7 crosses the finish line - InfoWorld
The latest version of Microsoft's strongly typed JavaScript introduces support for ECMAScript modules in Node.js, adds coding enhancements.
Read more >
What's new in TypeScript 4.7? - The Tech Platform
TypeScript 4.7, now in a beta release, offers ECMAScript module (ESM) support for Node.js 12 as well as a multitude of coding enhancements....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found