maloguertin / msw-trpc

tPRC support for MSW
208 stars 21 forks source link

`req.getInput()` should indicate that its return type is a promise for mutations #17

Closed jack-michaud closed 1 year ago

jack-michaud commented 1 year ago

Describe the bug req.getInput() should indicate that its return type is a promise for mutations. Incorrect typing will also mean someone attempting to get the input without awaiting this promise will get unexpected behavior.

To Reproduce Create a mocked server where a mutation is used.

const server = setupServer(
  trpcMsw.example.hello.mutation(async (req, res, ctx) => {
    const request = await req.getInput(); // warning
    return res(
      ctx.status(200),
      ctx.data({
        greeting: `Hello ${request.text}!`,
      })
    );
  })
);

Observe the warning: 'await' has no effect on the type of this expression.

An example repo can be found here. Link to the line with the warning

Expected behavior Since getInput() returns a promise for mutations, it the type returned from getInput() should be a promise.

Versions typescript: v5.0.4 tRPC: v10.22.0 msw: v1.2.1

maloguertin commented 1 year ago

Hi, this should already be the case, this is from the tests in this repo:

Screenshot 2023-06-29 at 8 16 37 AM

I will take a look at your repo.

maloguertin commented 1 year ago

This fix was already released in https://github.com/maloguertin/msw-trpc/releases/tag/v1.3.3 please upgrade your version :)