Skip to content

Commit 6894569

Browse files
committed
fix: make types for modify route config more accurate
1 parent 87f8c9b commit 6894569

File tree

4 files changed

+11
-8
lines changed

4 files changed

+11
-8
lines changed

packages/fetch-mock/src/FetchMock.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Route, {
33
RouteName,
44
UserRouteConfig,
55
RouteResponse,
6-
NullableUserRouteConfig,
6+
ModifyRouteConfig,
77
} from './Route.js';
88
import { MatcherDefinition, RouteMatcher } from './Matchers.js';
99
import CallHistory from './CallHistory.js';
@@ -148,7 +148,7 @@ export class FetchMock {
148148
return this;
149149
}
150150

151-
modifyRoute(routeName: string, options: NullableUserRouteConfig) {
151+
modifyRoute(routeName: string, options: ModifyRouteConfig) {
152152
this.router.modifyRoute(routeName, options);
153153
return this;
154154
}

packages/fetch-mock/src/Route.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ export type InternalRouteConfig = {
3939
};
4040
export type UserRouteConfig = UserRouteSpecificConfig & FetchMockGlobalConfig;
4141
type Nullable<T> = { [K in keyof T]: T[K] | null };
42-
export type NullableUserRouteConfig = Nullable<UserRouteConfig>;
42+
export type ModifyRouteConfig = Omit<
43+
Nullable<UserRouteSpecificConfig>,
44+
'name' | 'sticky'
45+
>;
4346

4447
export type RouteConfig = UserRouteConfig &
4548
FetchImplementations &
@@ -124,7 +127,7 @@ class Route {
124127
this.init(config);
125128
}
126129

127-
init(config: RouteConfig | NullableUserRouteConfig) {
130+
init(config: RouteConfig | ModifyRouteConfig) {
128131
this.config = config;
129132
this.#sanitize();
130133
this.#validate();

packages/fetch-mock/src/Router.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import Route, {
66
RouteResponse,
77
RouteResponseData,
88
RouteResponseConfig,
9-
NullableUserRouteConfig,
9+
ModifyRouteConfig,
1010
} from './Route.js';
1111
import { isUrlMatcher, isFunctionMatcher } from './Matchers.js';
1212
import { RouteMatcher } from './Matchers.js';
@@ -385,7 +385,7 @@ export default class Router {
385385
}
386386
}
387387

388-
modifyRoute(routeName: string, options: NullableUserRouteConfig) {
388+
modifyRoute(routeName: string, options: ModifyRouteConfig) {
389389
const route = this.routes.find(
390390
({ config: { name } }) => name === routeName,
391391
);
@@ -400,7 +400,7 @@ export default class Router {
400400
);
401401
}
402402

403-
if (options.name) {
403+
if ('name' in options) {
404404
throw new Error(
405405
`Cannot rename the route \`${routeName}\` as \`${options.name}\`: renaming routes is not supported`,
406406
);

packages/fetch-mock/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export {
55
} from './FetchMock.js';
66
export { CallHistoryFilter, CallLog } from './CallHistory.js';
77
export { RouteMatcher, MatcherDefinition } from './Matchers.js';
8-
export { UserRouteConfig, RouteResponse, RouteName } from './Route.js';
8+
export { UserRouteConfig, RouteResponse, RouteName, ModifyRouteConfig } from './Route.js';
99
export { RemoveRouteOptions } from './Router.js';
1010

1111
import fetchMock from './FetchMock.js';

0 commit comments

Comments
 (0)