paoloricciuti / sveltekit-search-params

The easiest way to read and WRITE from query parameters in sveltekit.
https://sveltekit-search-params.netlify.app
MIT License
478 stars 13 forks source link

Array helper default value not typed correctly #44

Closed ajhaupt7 closed 8 months ago

ajhaupt7 commented 9 months ago

Describe the bug

Thanks for this awesome library!

Simple issue - the default value of an array param when using the ssp.array() helper is not typed correctly.

Currently we have

    array: <T = any>(defaultValue?: T) => ({
        encode: (value: T[]) => JSON.stringify(value),
        decode: (value: string | null): T[] | null => {
            if (value === null) return null;
            try {
                return JSON.parse(value);
            } catch (e) {
                return null;
            }
        },
        defaultValue,
    }),

The default value should be typed as T[] and not T.

Reproduction

-

Logs

No response

philmas commented 8 months ago

How did you solve this issue? I also have this issue.