Skip to content

Commit

Permalink
Fix BaseHandler type, re-arrange a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
IanVS committed Aug 11, 2023
1 parent c9bb9bb commit 2e214af
Showing 1 changed file with 18 additions and 27 deletions.
45 changes: 18 additions & 27 deletions lib/msw-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<AnyRegistry> | {};
Expand All @@ -29,12 +25,23 @@ type HTTPVerb =
| 'options'
| 'head';

type BaseHandler = (
path: string,
// TODO: infer registry
handler?: RouteHandler<AnyRegistry>,
options?: HandlerOptions
) => void;
/** e.g. "/movies/:id" */
type Shorthand = string;

type RouteArgs =
| [RouteOptions]
| [Record<string, unknown>, 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: (
Expand Down Expand Up @@ -94,22 +101,6 @@ function isOption(option: unknown): option is RouteOptions {
return false;
}

/** e.g. "/movies/:id" */
type Shorthand = string;

type RouteArgs =
| [RouteOptions]
| [Record<string, unknown>, ResponseCode]
| [Function, ResponseCode]
| [Shorthand, RouteOptions]
| [Shorthand, ResponseCode, RouteOptions];

type RouteArguments = [
RawHandler | undefined,
ResponseCode | undefined,
RouteOptions,
];

/**
* Extract arguments for a route.
*
Expand Down

0 comments on commit 2e214af

Please sign in to comment.