New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[react-router] ExtractRouteParams
breaks with custom matchers
#52914
Comments
Some patterns now may be possible with #52712 however it doesn't cover all cases. An example:
This fails because the initial split uses DefinitelyTyped/types/react-router/index.d.ts Line 152 in 334dd10
Unfortunately this seems to be going down the hole of implementing RegExp pattern matching in TypeScript string literals. 😱 |
Perhaps we remove these type restrictions, and have like a The problem with the forward slash seems mute 👀, can't it just infer like That'll solve this no? |
Possibly. Start with the most specific pattern for The key names may also need to be cleaned up. There's also the technical possibility of having a |
@beaucollins thanks for jumping in this! 🥰 |
It's @lmichelin who landed #52712 so thanks to them! |
I just upgraded my project to post-#52712 types (@types/react-router@5.1.16) and I'm now getting TS errors that may be related to #52914 (comment) above. The first segment in the path seems to be extracted correctly, but the second segment is extracted with the prop name being extracted as the whole regex (e.g. I assume that the problem is that the final forward-slash in my URL pattern is optional ( Any ideas for how to work around this? cc @lmichelin @beaucollins Here's the relevant lines of my JSX: <Route
path="/times/:v(day|list)/:d(\\d{8})(/)?"
render={(routeProps: RouteComponentProps<{ d: string; v: string }>) => { The
|
@justingrant You can cast it to something that <Route
path={"/times/:v(day|list)/:d(\\d{8})(/)?" as "/times/:v/:d"}
render={(routeProps: RouteComponentProps<{ d: string; v: string }>) => { |
Great hack! Works well and is reasonably self-describing. Thx. |
React-rotuer's
generatePath
method just proxiespath-to-regexp
, which supports custom matchers.Currently the typescript fails when asking for
generatePath('/abc/:xyz([a-z])?', { xyz: 'a'})
<- should be valid. But fails.cc @mrk21 @vasek17 @ngbrown @awendland @KostyaEsmukov @johnnyreilly @LKay @DovydasNavickas @Nguyen @Grmiade @DaIgeb @egorshulga @rraina @t49tran @8enSmith @wezleytsai @eps1lon @HipsterBrown @pawfa
The text was updated successfully, but these errors were encountered: