Skip to content

Commit

Permalink
chore: types for core all done I think
Browse files Browse the repository at this point in the history
  • Loading branch information
wheresrhys committed Jul 24, 2024
1 parent a650023 commit f8c1168
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
npm run lint
npm run lint && npm run types:lint && npm run types:check
1 change: 1 addition & 0 deletions packages/core/src/CallHistory.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class CallHistory {
* @param {Router} router
*/
constructor(globalConfig, router) {

/** @type {CallLog[]} */
this.callLogs = [];
this.config = globalConfig;
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/Matchers.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
normalizeUrl,
} from './RequestUtils.js';


/** @typedef {string | RegExp | URL} RouteMatcherUrl */
/** @typedef {function(string): RouteMatcherFunction} UrlMatcherGenerator */
/** @typedef {function(CallLog): boolean} RouteMatcherFunction */
Expand Down Expand Up @@ -213,7 +214,6 @@ const getFullUrlMatcher = (route, matcherUrl, query) => {
};
};


/**
* @type {MatcherGenerator}
*/
Expand Down
1 change: 0 additions & 1 deletion packages/core/types/FetchMock.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export type RouteResponse = import("./Router").RouteResponse;
export type MatcherDefinition = import("./Matchers").MatcherDefinition;
export type CallLog = import("./CallHistory").CallLog;
export type RouteResponseFunction = import("./Route").RouteResponseFunction;
export type AdditionalRouteMethodName = "get" | "post" | "put" | "delete" | "head" | "patch" | "once" | "sticky" | "any" | "anyOnce" | "getOnce" | "postOnce" | "putOnce" | "deleteOnce" | "headOnce" | "patchOnce";
export type FetchMockConfig = {
sendAsJson?: boolean;
includeContentLength?: boolean;
Expand Down
18 changes: 18 additions & 0 deletions packages/core/types/InstanceManagement.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
type RequestConstructor = new (input: string | Request, init ?: RequestInit) => Request;

declare type FetchMockCore ={
createInstance: () => FetchMock
config: FetchMockConfig;
}

declare type FetchMock = FetchMockCore & Router

// 5. Declaration merging
// Unlike a type alias, an interface can be defined multiple times, and will be treated as a single interface(with members of all declarations being merged).

// // These two declarations become:
// // interface Point { x: number; y: number; }
// interface Point { x: number; }
// interface Point { y: number; }

// const point: Point = { x: 1, y: 2 };
1 change: 0 additions & 1 deletion packages/core/types/RequestUtils.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ export function createCallLogFromUrlAndOptions(url: string | object, options: Re
export function createCallLogFromRequest(request: Request, options: RequestInit): Promise<CallLog>;
export function getPath(url: string): string;
export function getQuery(url: string): string;
export function isRequest(urlOrRequest: string | Request, Request: typeof globalThis.Request): urlOrRequest is Request;
export function normalizeHeaders(headers: Headers | [string, string][] | Record<string, string> | {
[x: string]: string | number;
} | HeadersInit): {
Expand Down

0 comments on commit f8c1168

Please sign in to comment.