-
Notifications
You must be signed in to change notification settings - Fork 1k
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
[Router] Fix TS error when passing WrapperProps to <PrivateSet>
s
#11739
Conversation
70f4450 enables the pretty helpful TSDOC info on the |
Would be cool to have this in v8.4.2 🙏 |
BTW, the same result as above two commits could also be achieved a little simpler: export declare function Set<WrapperProps>(props: SetProps<WrapperProps>): React.JSX.Element;
type PrivateSetProps = {
/** The page name where a user will be redirected when not authenticated */
unauthenticated: string;
};
/** @deprecated Please use `<PrivateSet>` instead */
export declare function Private<WrapperProps>(props: SetProps<WrapperProps> | PrivateSetProps): React.JSX.Element;
export declare function PrivateSet<WrapperProps>(props: SetProps<WrapperProps> | PrivateSetProps): React.JSX.Element; … but this may not communicate the intent of the authors as clearly. |
I've confirmed the issue, and verified the fix. Fixing this seems to have brought up another issue though
And if you look inside type LayoutProps = {
title: string
titleTo: keyof typeof routes
buttonLabel: string
buttonTo: keyof typeof routes
children: React.ReactNode
}
const ScaffoldLayout = ({
title,
titleTo,
buttonLabel,
buttonTo,
children,
}: LayoutProps) => { Where To fix that I have to either declare a separate variable with the expected type, or do a type cast. Like this: const userExamplesName: RouteName = 'userExamples'
return (
<Router>
<PrivateSet unauthenticated="home" wrap={ScaffoldLayout} title="UserExamples" titleTo={userExamplesName} buttonLabel="New UserExample" buttonTo={'newUserExample' as RouteName}>
<Route path="/user-examples/new" page={UserExampleNewUserExamplePage} name="newUserExample" /> @Philzen Are you also seeing this issue? Or is it just something on my side? |
I'm not sure i have that kind of complex layout file to test at hand atm. However, just as a double check that the root cause lies in this PR, does this also happen when you use a |
Yes, it does. So let's ignore this issue for this PR. (Honestly I'm pretty sure it was a misstake to add the ability to spread props onto |
Not expecting you to do this, but if you wanted to test all you have to do is use the scaffold generator for any model and you should see the problem |
Thx for the hint, i could reproduce it. One really peculiar finding: Try |
The same TS error that you were reporting, reproducible on a
Yes of course, as unauthenticated is required here. But as i can see on your screenshot, the TS error on |
Gotcha. On |
Redwood v6.4 deprecated the
unauthorized
prop on<Set>
s so during that upgrade we migrated to<PrivateSet>
as per the release notes.Since then any props forwarded to a
wrap={MyWrapper}
component show up as TypeScript errors. While hovering over thewrap
prop of a<Set>
correctly infersWrapperType<MyWrapper>
, hovering over thewrap
prop of a<PrivateSet>
givesWrapperType<unknown>
I'm a bit surprised to see that TypeScript's
Omit
drops the props derived via the generic fromSet
here 🤯 … could not find anything explaining that behavior in the docs, so would be glad to learn why that happens (otherwise feels a bit like a typescript bug?).Simply adding them again as an intersection types does the job and gets rid of the typescript error (e738350) 🚀