From 9f639f912c6a6a9acfa8ef418ee7b0e9305ef6b0 Mon Sep 17 00:00:00 2001 From: Vuong Phan <13298232+thevuong@users.noreply.github.com> Date: Tue, 24 Oct 2023 21:36:51 +0700 Subject: [PATCH] feat: make `parseStringParam` return type depend on `defaultValue` --- packages/lib/src/search-params.ts | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/packages/lib/src/search-params.ts b/packages/lib/src/search-params.ts index fe9a543..c9148ba 100644 --- a/packages/lib/src/search-params.ts +++ b/packages/lib/src/search-params.ts @@ -10,19 +10,19 @@ function parseQueryValues(value: string[] | string): string[] { return Array.isArray(value) ? value : [value]; } -export function parseStringParam( +export function parseStringParam( paramValue: string[] | string | undefined, - defaultValue: string | undefined = undefined, -): string | undefined { + defaultValue: T = undefined as T, +): string | T { const parsedValue = parseQueryValue(paramValue); return parsedValue || defaultValue; } -export function parseNumberParam( +export function parseNumberParam( paramValue: string[] | string | undefined, - defaultValue: number | undefined = NaN, -): number { + defaultValue: T = undefined as T, +): number | T { const parsedValue = parseQueryValue(paramValue); return Number(parsedValue) || defaultValue; @@ -37,10 +37,10 @@ export function parseJoinedStringParam( return parsedValue?.split(separator) || []; } -export function parseStringParams( +export function parseStringParams( paramValue: string[] | string | undefined, - defaultValue: string[] | undefined = undefined, -): string[] | undefined { + defaultValue: T = undefined as T, +): string[] | T { if (!paramValue || paramValue.length === 0) { return defaultValue; } @@ -48,10 +48,10 @@ export function parseStringParams( return parseQueryValues(paramValue); } -export function parseNumberParams( +export function parseNumberParams( paramValue: string[] | string | undefined, - defaultValue: number[] | undefined = undefined, -): number[] | undefined { + defaultValue: T = undefined as T, +): number[] | T { if (!paramValue) { return defaultValue; }