From 2e214afaeae01b72385575199d85368f9444d1d5 Mon Sep 17 00:00:00 2001 From: Ian VanSchooten Date: Fri, 11 Aug 2023 17:02:42 -0400 Subject: [PATCH] Fix BaseHandler type, re-arrange a bit --- lib/msw-config.ts | 45 ++++++++++++++++++--------------------------- 1 file changed, 18 insertions(+), 27 deletions(-) diff --git a/lib/msw-config.ts b/lib/msw-config.ts index abd4691..ada59c8 100644 --- a/lib/msw-config.ts +++ b/lib/msw-config.ts @@ -6,11 +6,7 @@ import { type SetupWorkerApi, } from 'msw'; import type { Server } from 'miragejs'; -import type { - HandlerOptions, - RouteHandler, - ServerConfig, -} from 'miragejs/server'; +import type { RouteHandler, ServerConfig } from 'miragejs/server'; import type { AnyFactories, AnyModels, AnyRegistry } from 'miragejs/-types'; type RawHandler = RouteHandler | {}; @@ -29,12 +25,23 @@ type HTTPVerb = | 'options' | 'head'; -type BaseHandler = ( - path: string, - // TODO: infer registry - handler?: RouteHandler, - options?: HandlerOptions -) => void; +/** e.g. "/movies/:id" */ +type Shorthand = string; + +type RouteArgs = + | [RouteOptions] + | [Record, ResponseCode] + | [Function, ResponseCode] + | [Shorthand, RouteOptions] + | [Shorthand, ResponseCode, RouteOptions]; + +type RouteArguments = [ + RawHandler | undefined, + ResponseCode | undefined, + RouteOptions, +]; + +type BaseHandler = (path: string, ...args: RouteArgs) => void; type MirageServer = { registerRouteHandler: ( @@ -94,22 +101,6 @@ function isOption(option: unknown): option is RouteOptions { return false; } -/** e.g. "/movies/:id" */ -type Shorthand = string; - -type RouteArgs = - | [RouteOptions] - | [Record, ResponseCode] - | [Function, ResponseCode] - | [Shorthand, RouteOptions] - | [Shorthand, ResponseCode, RouteOptions]; - -type RouteArguments = [ - RawHandler | undefined, - ResponseCode | undefined, - RouteOptions, -]; - /** * Extract arguments for a route. *