Why createEnumParam doesn't strongly-type the `setParam` function?
Shaddix opened this issue · comments
Artur Drobinskiy commented
Here's the definition of createEnumParam
:
export const createEnumParam = <T extends string>(
enumValues: T[]
): QueryParamConfig<string | null | undefined, T | null | undefined>
Is there any reason why return type of it isn't QueryParamConfig<T | null | undefined, T | null | undefined>
(the first generic changed from string | null | undefined
to T | null | undefined
?
For me the latter seems more correct, as it allows strong-typing of setParam
function .
Artur Drobinskiy commented
My use case:
const MyParam = createEnumParamTyped<'one' | 'two'>([
'one',
'two',
]);
const [param, setParam] = useQueryParam('paramName', MyParam);
Here param
is properly typed ('one' | 'two' | ...
), but setParam
isn't (I can pass any string to it)
Peter Beshai commented
Fixed in #198