Skip to content
This repository has been archived by the owner on Feb 16, 2024. It is now read-only.

Commit

Permalink
Revert "Delete README.md"
Browse files Browse the repository at this point in the history
This reverts commit ee1df86.
  • Loading branch information
mohab-sameh committed Dec 21, 2023
1 parent ee1df86 commit 31bb457
Showing 1 changed file with 119 additions and 0 deletions.
119 changes: 119 additions & 0 deletions codemods/msw/2/type-args/README.md
Original file line number Diff line number Diff line change
@@ -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<ReqBodyType, PathParamsType>('/resource', (req, res, ctx) => {
return res(ctx.json({ firstName: 'John' }));
});
```

### After

```ts
http.get<PathParamsType, ReqBodyType>('/resource', (req, res, ctx) => {
return res(ctx.json({ firstName: 'John' }));
});
```

### Before

```ts
http.get<ReqBodyType>('/resource', (req, res, ctx) => {
return res(ctx.json({ firstName: 'John' }));
});
```

### After

```ts
http.get<any, ReqBodyType>('/resource', (req, res, ctx) => {
return res(ctx.json({ firstName: 'John' }));
});
```

### Before

```ts
const handlers: RestHandler<DefaultBodyType>[] = [
http.get('/resource', (req, res, ctx) => {
return res(ctx.json({ firstName: 'John' }));
}),
];
```

### After

```ts
const handlers: HttpHandler[] = [
http.get<any, DefaultBodyType>('/resource', (req, res, ctx) => {
return res(ctx.json({ firstName: 'John' }));
}),
];
```

### Before

```ts
export function mockFactory(
url: string,
resolver: ResponseResolver<
MockedRequest<{ id: string }>,
RestContext,
Awaited<ImportedPromiseBodyType>
>,
) {
return http.get(url, resolver);
};
```

### After

```ts
export function mockFactory(
url: string,
resolver: ResponseResolver<
HttpRequestResolverExtras<PathParams>,
{ id: string },
Awaited<ImportedPromiseBodyType>
>,
) {
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)

0 comments on commit 31bb457

Please sign in to comment.