BUG | `useRouteParams` | useRouteParams infers transform parameter type from defaultValue
Describe the bug
because of the signature
`declare function useRouteParams< T extends RouteParamValueRaw = RouteParamValueRaw, K = T
( name: string, defaultValue?: MaybeRefOrGetter, options?: ReactiveRouteOptionsWithTransform<T, K> ): Ref;`
The inferred type of the transform value is equal to the default value:
const employeeFilter = useRouteParams('employeeId', null, { transform: (value) => (!value ? null : Number(value)), });
e.g. with the above method the type for value is inferred as null (see reproduction)
Expected behaviour: Typing should be updated to be correct. I am not sure what is the best approach, are raw route params not always string/undefined? so maybe that would work? Otherwise, inferring the type to any/unknown I would also consider to be an improvement.
Reproduction
System Info
System:
OS: Windows 11 10.0.26200
CPU: (8) x64 11th Gen Intel(R) Core(TM) i7-1185G7 @ 3.00GHz
Memory: 10.81 GB / 31.73 GB
Binaries:
Node: 24.18.0 - C:\nvm4w\nodejs\node.EXE
npm: 11.16.0 - C:\nvm4w\nodejs\npm.CMD
pnpm: 11.17.0 - C:\nvm4w\nodejs\pnpm.CMD
Browsers:
Chrome: 151.0.7922.138
Edge: Chromium (151.0.4129.78)
npmPackages:
@vueuse/core: 14.3.0 => 14.3.0
@vueuse/router: 14.3.0 => 14.3.0
vue: 3.5.40 => 3.5.40
Used Package Manager
pnpm
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Make sure this is a VueUse issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to https://github.com/vuejs/core instead.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion.
- The provided reproduction is a minimal reproducible example of the bug.
Source: vueuse/vueuse