Type error in Document.getInitialProps? #11927
Replies: 9 comments
-
I don't think so. I believe that |
Beta Was this translation helpful? Give feedback.
-
@justincy Thanks for the feedback. It looks to me like I had a typo above, I meant
|
Beta Was this translation helpful? Give feedback.
-
Sort of. They both get passed into the component, but their source is different. Perhaps you're hinting at the need for Document (and App, for that matter) to have a second generic that represents the type of data returned from |
Beta Was this translation helpful? Give feedback.
-
Yes, that might be helpful. Is IP for initialProps? I still don’t understand why the source of the props is an important distinction. Is there a use case or example you can guide me to that demonstrates a situation where the interface should change based on context? That seems to oppose the very goal of interfaces. |
Beta Was this translation helpful? Give feedback.
-
Put another way, when is it ever okay for getInitialProps to return props that violate the component’s interface? |
Beta Was this translation helpful? Give feedback.
-
Great questions. You are right that Did I explain that well? |
Beta Was this translation helpful? Give feedback.
-
That's how I understand it, but I could be wrong. |
Beta Was this translation helpful? Give feedback.
-
But as I think about it, we never use Document, App, or Pages directly in JSX because Next just takes care of it for us, so I don't think I actually know what the purpose of |
Beta Was this translation helpful? Give feedback.
-
Yes you did, thank you. I understand the point you're making, but it seems to me that So I'm back to thinking that the custom props type for Document and App should match the props that And more generally, to me the purpose of an interface is to decouple a component from its contextual usage, and for that reason, the props are the props regardless of how they are initialized (JSX, SSR, Redux, whatever else). |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Bug report
Describe the bug
I noticed that the definition of
getInitialProps
could be more expressive.I think it should be
<DocumentInitialProps & P>
Beta Was this translation helpful? Give feedback.
All reactions