TypeScript 4.7 compat
See original GitHub issuePrerequisites
- I confirm my issue is not in the opened issues
- I confirm the Frequently Asked Questions didn’t contain the answer to my issue
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:
- Created a year ago
- Reactions:2
- Comments:7 (6 by maintainers)
Top GitHub Comments
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!
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.