I'm aiming to enhance an MSW resolver by applying response composition and creating a new resolver.
import {
ResponseResolver,
context,
createResponseComposition,
response
} from "msw";
export const createDelayedComposer = <
M extends ResponseResolver<any, any, any>
>(
milliseconds: number
) => {
const delayed = createResponseComposition(undefined, [
context.delay(milliseconds)
]);
return (resolver: M): M => (req, _, ctx) =>
resolver(req, Object.assign(delayed, response), ctx);
};
Encountering the following error:
Type '(req: any, _: ResponseComposition<any>, ctx: any) => AsyncResponseResolverReturnType<MockedResponse<any>>' is not assignable to type 'M'.
'(req: any, _: ResponseComposition<any>, ctx: any) => AsyncResponseResolverReturnType<MockedResponse<any>>' is assignable to the constraint of type 'M', but 'M' could be instantiated with a different subtype of constraint 'ResponseResolver<any, any, any>'.ts(2322)
I've looked into similar solutions but I'm having trouble understanding my mistake. Can anyone identify what's wrong with my signature, and suggest a fix?
Alternatively, perhaps there's another approach to achieve the objective of enhancing the resolver function