-
Notifications
You must be signed in to change notification settings - Fork 27.2k
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
Parameter on AppType
is used incorrectly
#42846
Comments
Hey! I'd like to take this one. |
There is a slight runtime difference between |
Should we extend the type and allow to pass two generics - for |
I don't don't think that's needed. |
Hi Guys, is this issue fixed? |
@DarkShadow20 Hi. There's one draft PR and one open & ready, which is mine, but they don't get much attention/priority. |
I tried to solve the issue. Here is the output. props.foo: bar Here is the code link: https://codesandbox.io/s/upbeat-shtern-zzdhqm?file=/pages/_app.tsx |
Parameter on AppType is used incorrectly #42846 In the provided sandbox, you worked on addressing an issue related to the use of AppType. The issue was causing unexpected behavior in the props received by the MyApp component. After my modifications, I observed the following output: props.foo: undefined Here's the link of the sandbox: https://codesandbox.io/p/devbox/bitter-water-p25rr5?embed=1&file=%2Fpages%2F_app.tsx |
For: #42846 const MyApp: AppType<MyInitialProps> = (props: any) => {
return (
<div>
<props.Component {...props.pageProps} />
<hr />
<p>{`props.foo: ${props.foo}`}</p>
<p>{`props.pageProps.foo: ${props.pageProps.foo}`}</p>
</div>
);
};
MyApp.getInitialProps = async (ctx: any) => {
const props = await App.getInitialProps(ctx); // <--another separate issue
return {
...props,
foo: "bar" // TS complains MyApp type is wrong if this line is excluded
};
}; |
@RonakShishangia Using |
#42846
Therefore, MyInitialProps is the type of props.pageProps. If you want to use props.foo, the type of props needs to be extended. I hope this is helpful to you. Thank you. |
you can see what I comment,thank you |
Verify canary release
Provide environment information
environment information
Note: warning at the end seems to be because I'm using
next@canary
(as instructed) butcanary
version is older than latest official release. My issue is present in either version.Describe the Bug
Prop types defined by the parameter on
AppType
are incorrectly applied to MyApp'sprops.pageProps
instead of MyApp'sprops
.Expected Behavior
Expected TS types to correctly reflect runtime types.
Link to reproduction
https://codesandbox.io/s/polished-tree-xhvisb?file=/pages/_app.tsx
To Reproduce
There's a TS error on line 13, complaining
Property 'foo' does not exist on type 'AppPropsType<any, MyInitialProps>'
, even thoughprops.foo
does exist at runtime.Also, there's no TS error on line 14, even though
props.pageProps.foo
does not exist at runtime.The text was updated successfully, but these errors were encountered: