11// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
22// This file will be automatically regenerated when your Next.js server is running.
3- // nextjs-routes version: 1 .0.8
3+ // nextjs-routes version: 2 .0.0
44/* eslint-disable */
55
66// prettier-ignore
77declare module "nextjs-routes" {
8+ import type {
9+ GetServerSidePropsContext as NextGetServerSidePropsContext ,
10+ GetServerSidePropsResult as NextGetServerSidePropsResult
11+ } from "nextjs" ;
12+
813 export type Route =
914 | DynamicRoute < "/api/as-api/[...asProxy]" , { "asProxy" : string [ ] } >
1015 | DynamicRoute < "/api/auth/[...auth0]" , { "auth0" : string [ ] } >
@@ -67,6 +72,33 @@ declare module "nextjs-routes" {
6772 * route({ pathname: "/foos/[foo]", query: { foo: "bar" }}) will produce "/foos/bar".
6873 */
6974 export declare function route ( r : Route ) : string ;
75+
76+ /**
77+ * Nearly identical to GetServerSidePropsContext from next, but further narrows
78+ * types based on nextjs-route's route data.
79+ */
80+ export type GetServerSidePropsContext <
81+ Pathname extends Route [ "pathname" ] = Route [ "pathname" ] ,
82+ Preview extends NextGetServerSidePropsContext [ "previewData" ] = NextGetServerSidePropsContext [ "previewData" ]
83+ > = Omit < NextGetServerSidePropsContext , 'params' | 'query' | 'defaultLocale' | 'locale' | 'locales' > & {
84+ params : Extract < Route , { pathname : Pathname } > [ "query" ] ;
85+ query : Query ;
86+ defaultLocale ?: undefined ;
87+ locale ?: Locale ;
88+ locales ?: undefined ;
89+ } ;
90+
91+ /**
92+ * Nearly identical to GetServerSideProps from next, but further narrows
93+ * types based on nextjs-route's route data.
94+ */
95+ export type GetServerSideProps <
96+ Props extends { [ key : string ] : any } = { [ key : string ] : any } ,
97+ Pathname extends Route [ "pathname" ] = Route [ "pathname" ] ,
98+ Preview extends NextGetServerSideProps [ "previewData" ] = NextGetServerSideProps [ "previewData" ]
99+ > = (
100+ context : GetServerSidePropsContext < Pathname , Preview >
101+ ) => Promise < NextGetServerSidePropsResult < Props > >
70102}
71103
72104// prettier-ignore
@@ -81,13 +113,12 @@ declare module "next/link" {
81113 } from "react" ;
82114 export * from "next/dist/client/link" ;
83115
84- type Query = { query ?: { [ key : string ] : string | string [ ] | undefined } } ;
85116 type StaticRoute = Exclude < Route , { query : any } > [ "pathname" ] ;
86117
87118 export interface LinkProps
88119 extends Omit < NextLinkProps , "href" | "locale" > ,
89120 AnchorHTMLAttributes < HTMLAnchorElement > {
90- href : Route | StaticRoute | Query ;
121+ href : Route | StaticRoute | Omit < Route , "pathname" >
91122 locale ?: false ;
92123 }
93124
@@ -115,34 +146,49 @@ declare module "next/router" {
115146
116147 type NextTransitionOptions = NonNullable < Parameters < Router [ "push" ] > [ 2 ] > ;
117148 type StaticRoute = Exclude < Route , { query : any } > [ "pathname" ] ;
118- type Query = { query ?: { [ key : string ] : string | string [ ] | undefined } } ;
119149
120150 interface TransitionOptions extends Omit < NextTransitionOptions , "locale" > {
121151 locale ?: false ;
122152 }
123153
154+ type PathnameAndQuery < Pathname > = Required <
155+ Pick < Extract < Route , { pathname : Pathname } > , "pathname" | "query" >
156+ > ;
157+
158+ type AutomaticStaticOptimizedQuery < PaQ > = Omit < PaQ , "query" > & {
159+ query : Partial < PaQ [ "query" ] > ;
160+ } ;
161+
162+ type BaseRouter < PaQ > =
163+ | ( { isReady : false } & AutomaticStaticOptimizedQuery < PaQ > )
164+ | ( { isReady : true } & PaQ ) ;
165+
124166 export type NextRouter < P extends Route [ "pathname" ] = Route [ "pathname" ] > =
125- Extract < Route , { pathname : P } > &
167+ BaseRouter < PathnameAndQuery < P > > &
126168 Omit <
127169 Router ,
128- | "push"
129- | "replace"
130- | "locale"
131- | "locales"
132170 | "defaultLocale"
133171 | "domainLocales"
172+ | "isReady"
173+ | "locale"
174+ | "locales"
175+ | "pathname"
176+ | "push"
177+ | "query"
178+ | "replace"
179+ | "route"
134180 > & {
135181 defaultLocale ?: undefined ;
136182 domainLocales ?: undefined ;
137183 locale ?: Locale ;
138184 locales ?: undefined ;
139185 push (
140- url : Route | StaticRoute | Query ,
186+ url : Route | StaticRoute | Omit < Route , "pathname" > ,
141187 as ?: string ,
142188 options ?: TransitionOptions
143189 ) : Promise < boolean > ;
144190 replace (
145- url : Route | StaticRoute | Query ,
191+ url : Route | StaticRoute | Omit < Route , "pathname" > ,
146192 as ?: string ,
147193 options ?: TransitionOptions
148194 ) : Promise < boolean > ;
0 commit comments