Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

req.getInput incorrectly typed for query #25

Open
DavidAmmeraal opened this issue Aug 18, 2023 · 2 comments
Open

req.getInput incorrectly typed for query #25

DavidAmmeraal opened this issue Aug 18, 2023 · 2 comments

Comments

@DavidAmmeraal
Copy link

Describe the bug

When mocking a query, and using req.getInput, TS incorrectly infers the type.

To Reproduce
I've created an example repo to reproduce the bug:

https://github.com/DavidAmmeraal/msw-trpc-bug/blob/main/src/example.ts

Given the following:

trpcMsw.post.byId.query((req, res, ctx) => {
    assert.equal(req.getInput(), { id: '1' });

    return res(
      ctx.status(200),
      ctx.data({
        id: '1',
        title: 'test',
        text: 'test',
        createdAt: new Date(),
        updatedAt: new Date(),
      }),
    );
  })

TS tells me that req.getInput should be of type:

(property) getInput: () => {
    id: string;
}

However, when running the code (using npx ts-node src/example.ts), the return value is instead:

{
  0: {
    json: {
      id: '1'
    }
}

Expected behavior

I would expect getInput to return a value of shape:

{
    id: string;
}

Versions
"@trpc/next": "^10.37.1",
"@trpc/react-query": "^10.37.1",
"@trpc/server": "^10.37.1",
"typescript": "^5.1.3",

@DavidAmmeraal
Copy link
Author

DavidAmmeraal commented Aug 18, 2023

This seems to occur when using httpBatchLink, when using httpLink this doesn't happen, and I also see you mention that batch is not supported in the README. Can be closed if no plans for this.

@maloguertin
Copy link
Owner

maloguertin commented Dec 8, 2023

This seems to occur when using httpBatchLink, when using httpLink this doesn't happen, and I also see you mention that batch is not supported in the README. Can be closed if no plans for this.

I would like to support httpBatchLink at some point since I actually use it and it would help to have tests that are closer to the real world usage of tRPC so I'll leave this open for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants