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
It automatically generates the type of the layout prop based on the folder name of the parallel route.
Currently for dynamic routes you need to manually give the params a type with the exact name of the folder.
It would be a nice improvement in DX, to have the same behavior for the params prop.
Proposal
Consider this file structure: app/admin/users/[userId]/posts/[postId]/page.tsx
Here the correct params type is:
params: {userId: string,postId: string}
Now let's rename the folder structure to this: app/admin/users/[userName]/posts/[postId]/page.tsx
In this case the typescript plugin would automatically be typed with the new key of userName and display errors in the IDE.
//page.tsxexportdefaultfunctionPostPage({params}){constpost=awaitsomeFunc(params.userId,params.postId)//^? Property 'userId' does not exist on type '{ userName: string; postId: string; }'}
The same applies to layout.tsx
In route.ts the second argument of the HTTP functions have the same types.
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
-
Goals
page.tsx
,layout.tsx
androute.ts
components automatically have the correctparams
prop object type based on the file structure.Background
Recently the new
@folder-name
convention received an ergonomic improvement on the typescript on the Layout component props, as shown in this tweet: https://twitter.com/delba_oliveira/status/1646906220660551681It automatically generates the type of the layout prop based on the folder name of the parallel route.
Currently for dynamic routes you need to manually give the
params
a type with the exact name of the folder.It would be a nice improvement in DX, to have the same behavior for the
params
prop.Proposal
Consider this file structure:
app/admin/users/[userId]/posts/[postId]/page.tsx
Here the correct params type is:
Now let's rename the folder structure to this:
app/admin/users/[userName]/posts/[postId]/page.tsx
In this case the typescript plugin would automatically be typed with the new key of
userName
and display errors in the IDE.The same applies to layout.tsx
In route.ts the second argument of the HTTP functions have the same types.
Beta Was this translation helpful? Give feedback.
All reactions