paoloricciuti / sveltekit-search-params

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

Type error with exactOptionalPropertyTypes on #63

Open dshook opened 11 months ago

dshook commented 11 months ago

Describe the bug

Given this code:

const booleanFilters = queryParam('bf', ssp.array<string>([]));

I get this typescript error when exactOptionalPropertyTypes is true in my tsconfig

Argument of type '{ encode: (value: string[]) => string; decode: (value: string | null) => string[] | null; defaultValue: string[] | undefined; }' is not assignable to parameter of type 'EncodeAndDecodeOptions<string[]>' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
  Types of property 'defaultValue' are incompatible.
    Type 'string[] | undefined' is not assignable to type 'string[]'.
      Type 'undefined' is not assignable to type 'string[]'.ts(2379)

Reproduction

import { ssp, queryParam } from 'sveltekit-search-params';

const booleanFilters = queryParam('bf', ssp.array<string>([]));

Logs

No response