You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I’ve been working with the generatePath function, and I noticed that the params type currently only accepts string | null:
params: {[keyinPathParam<Path>]: string|null;}
However, in many practical cases, route parameters can also be number values. For example:
generatePath("/users/:userId",{userId: 123});
While this works at runtime (since the internal stringify() safely handles numbers using String(p)), the current TypeScript definition doesn't allow this and causes a type error.
Would it make sense to update the type to support number as well, like this?
params: {
[key in PathParam<Path>]: string | number | null;
}
This change would better reflect real-world usage and eliminate the need for unnecessary String() casts at the call site.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
I’ve been working with the generatePath function, and I noticed that the params type currently only accepts string | null:
However, in many practical cases, route parameters can also be number values. For example:
While this works at runtime (since the internal stringify() safely handles numbers using String(p)), the current TypeScript definition doesn't allow this and causes a type error.
Would it make sense to update the type to support number as well, like this?
This change would better reflect real-world usage and eliminate the need for unnecessary String() casts at the call site.
Curious to hear your thoughts on this. Thanks!
Beta Was this translation helpful? Give feedback.
All reactions