Tests: fix fetch mock typings for type-aware checks

This commit is contained in:
Shakker
2026-02-17 14:34:41 +00:00
parent dd0b789669
commit 6bb9b0656f
2 changed files with 29 additions and 17 deletions

View File

@@ -1,6 +1,13 @@
export const withFetchPreconnect = <T extends (...args: unknown[]) => unknown>(
type FetchWithPreconnect = {
preconnect: (url: string, init?: { credentials?: RequestCredentials }) => void;
};
export function withFetchPreconnect<T extends typeof fetch>(fn: T): T & FetchWithPreconnect;
export function withFetchPreconnect<T extends object>(
fn: T,
): typeof fetch =>
Object.assign(fn, {
preconnect: () => {},
}) as unknown as typeof fetch;
): T & FetchWithPreconnect & typeof fetch;
export function withFetchPreconnect(fn: object) {
return Object.assign(fn, {
preconnect: (_url: string, _init?: { credentials?: RequestCredentials }) => {},
});
}