diff --git a/.gitignore b/.gitignore index 00ad5b1..359d7e9 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ dist/ npm tsc/ .DS_Store +.idea diff --git a/src/primitives.ts b/src/primitives.ts index a99c931..021c04e 100644 --- a/src/primitives.ts +++ b/src/primitives.ts @@ -5,15 +5,15 @@ import type { JSONValue, PathParams, SearchParams } from './types' * @param searchParams the query parameters * @returns the url with the query parameters added with the same type as the url */ -function addQueryToURL( - url: string | URL, +function addQueryToURL( + url: T, searchParams?: SearchParams, -): string | URL { +): T { if (!searchParams) return url if (typeof url === 'string') { const separator = url.includes('?') ? '&' : '?' - return `${url}${separator}${new URLSearchParams(searchParams)}` + return `${url}${separator}${new URLSearchParams(searchParams)}` as T } if (searchParams && url instanceof URL) { for (const [key, value] of new URLSearchParams(searchParams).entries()) {