-
Notifications
You must be signed in to change notification settings - Fork 23
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
Support for V11 #37
Comments
It seems to work with v11, just the types are borked. I tried to give it a go, but that typescript magic is out of my reach amd ChatGPT did not help: https://github.com/maloguertin/msw-trpc/blob/main/src/types.ts |
can confirm 👍 |
Took a bit, but here are the working types for v11 import type {
MutationProcedure,
QueryProcedure,
SubscriptionProcedure,
inferProcedureInput,
inferProcedureOutput
} from "@trpc/server/unstable-core-do-not-import";
type Any = any;
type Router = Record<string, QueryProcedure<Any> | MutationProcedure<Any> | SubscriptionProcedure<Any>>;
export type ExtractKeys<T, K extends keyof T = keyof T> = T[K] extends
| QueryProcedure<Any>
| MutationProcedure<Any>
| Router
? K
: never;
export type Query<T, K extends keyof T> = T[K] extends QueryProcedure<Any>
? {
query(input: inferProcedureInput<T[K]>): inferProcedureOutput<T[K]>; // : SetQueryHandler<T, K>;
}
: never;
export type Mutation<T, K extends keyof T> = T[K] extends MutationProcedure<Any>
? {
mutation(input: inferProcedureInput<T[K]>): inferProcedureOutput<T[K]>;
}
: never;
type ExtractProcedureHandler<
T,
K extends keyof T
> = T[K] extends MutationProcedure<Any>
? Mutation<T, K>
: T[K] extends QueryProcedure<Any>
? Query<T, K>
: T[K] extends Router
? MswTrpc<T[K]>
: never;
export type MswTrpc<T> = {
[key in keyof T as ExtractKeys<T, key>]: ExtractProcedureHandler<T, key>;
};
export const trpcMsw: MswTrpc<AppRouter> = createTRPCMsw<AppRouter>() as Any; WARNING The api is clearly marked as "unstable", but it works for me now. |
I have addressed this in #41 FYI @tomitrescak @carlhopf |
Any updates on why #41 cannot be merged at this time? |
@maloguertin Please take a look, thank you! |
This would be greatly appreciated! |
Looks like the PR is ready to be merged, or is there any blocker? We're also really eager to have the support for v11. |
Is your feature request related to a problem? Please describe.
V11 has now entered Beta. Unfortunately this package does not work out of the box with V11 and some work might be needed.
Describe the solution you'd like
support for MSW v11.
Describe alternatives you've considered
Remaining on V10 for the time being :P
Additional context
you can find a PR on my public project trying to make this bump:
PupoSDC/chair-flight#77
Thank you very much for this package! ❤️
The text was updated successfully, but these errors were encountered: