From 31bb4572259bf2f1f7b34ebd90c6f44926f5dcc1 Mon Sep 17 00:00:00 2001 From: Mohab Date: Thu, 21 Dec 2023 19:35:53 +0200 Subject: [PATCH] Revert "Delete README.md" This reverts commit ee1df8659c364ec473f7d718b87499d6d0d18406. --- codemods/msw/2/type-args/README.md | 119 +++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 codemods/msw/2/type-args/README.md diff --git a/codemods/msw/2/type-args/README.md b/codemods/msw/2/type-args/README.md new file mode 100644 index 00000000..947fce71 --- /dev/null +++ b/codemods/msw/2/type-args/README.md @@ -0,0 +1,119 @@ +# Move Generic Arguments and Body Type Casts + +## Description + +There is a change to generic type interface of `rest.method()` calls. This codemod puts the generic arguments in the correct order to keep type safety. + +### WARNING + +This codemod runs `.fixUnusedIdentifiers()` on a target source file. This would remove any unused declarations in the file. This is due to the atomicity of this mod, which blindly inserts the callback structure into each msw handler callback and then cleans up the variables that are not used anymore. + +## Example + +### Before + +```ts +http.get('/resource', (req, res, ctx) => { + return res(ctx.json({ firstName: 'John' })); +}); +``` + +### After + +```ts +http.get('/resource', (req, res, ctx) => { + return res(ctx.json({ firstName: 'John' })); +}); +``` + +### Before + +```ts +http.get('/resource', (req, res, ctx) => { + return res(ctx.json({ firstName: 'John' })); +}); +``` + +### After + +```ts +http.get('/resource', (req, res, ctx) => { + return res(ctx.json({ firstName: 'John' })); +}); +``` + +### Before + +```ts +const handlers: RestHandler[] = [ + http.get('/resource', (req, res, ctx) => { + return res(ctx.json({ firstName: 'John' })); + }), +]; +``` + +### After + +```ts +const handlers: HttpHandler[] = [ + http.get('/resource', (req, res, ctx) => { + return res(ctx.json({ firstName: 'John' })); + }), +]; +``` + +### Before + +```ts +export function mockFactory( + url: string, + resolver: ResponseResolver< + MockedRequest<{ id: string }>, + RestContext, + Awaited + >, +) { + return http.get(url, resolver); +}; +``` + +### After + +```ts +export function mockFactory( + url: string, + resolver: ResponseResolver< + HttpRequestResolverExtras, + { id: string }, + Awaited + >, +) { + return http.get(url, resolver); +}; +``` + +## Applicability Criteria + +MSW version >= 1.0.0 + +## Other Metadata + +### Codemod Version + +v1.0.0 + +### Change Mode + +**Assistive**: The automation partially completes changes. Human involvement is needed to make changes ready to be pushed and merged. + +### **Codemod Engine** + +[ts-morph](https://github.com/dsherret/ts-morph) + +### Estimated Time Saving + +~15 minutes per occurrence + +### Owner + +[Intuita](https://github.com/intuita-inc)