5
5
6
6
// prettier-ignore
7
7
declare module "nextjs-routes" {
8
- import type {
9
- GetServerSidePropsContext as NextGetServerSidePropsContext ,
10
- GetServerSidePropsResult as NextGetServerSidePropsResult
11
- } from "nextjs" ;
12
-
13
8
export type Route =
14
9
| StaticRoute < "/404" >
15
10
| StaticRoute < "/account/api-key" >
@@ -112,33 +107,6 @@ declare module "nextjs-routes" {
112
107
* route({ pathname: "/foos/[foo]", query: { foo: "bar" }}) will produce "/foos/bar".
113
108
*/
114
109
export declare function route ( r : Route ) : string ;
115
-
116
- /**
117
- * Nearly identical to GetServerSidePropsContext from next, but further narrows
118
- * types based on nextjs-route's route data.
119
- */
120
- export type GetServerSidePropsContext <
121
- Pathname extends Route [ "pathname" ] = Route [ "pathname" ] ,
122
- Preview extends NextGetServerSidePropsContext [ "previewData" ] = NextGetServerSidePropsContext [ "previewData" ]
123
- > = Omit < NextGetServerSidePropsContext , 'params' | 'query' | 'defaultLocale' | 'locale' | 'locales' > & {
124
- params : Extract < Route , { pathname : Pathname } > [ "query" ] ;
125
- query : Query ;
126
- defaultLocale ?: undefined ;
127
- locale ?: Locale ;
128
- locales ?: undefined ;
129
- } ;
130
-
131
- /**
132
- * Nearly identical to GetServerSideProps from next, but further narrows
133
- * types based on nextjs-route's route data.
134
- */
135
- export type GetServerSideProps <
136
- Props extends { [ key : string ] : any } = { [ key : string ] : any } ,
137
- Pathname extends Route [ "pathname" ] = Route [ "pathname" ] ,
138
- Preview extends NextGetServerSideProps [ "previewData" ] = NextGetServerSideProps [ "previewData" ]
139
- > = (
140
- context : GetServerSidePropsContext < Pathname , Preview >
141
- ) => Promise < NextGetServerSidePropsResult < Props > >
142
110
}
143
111
144
112
// prettier-ignore
@@ -153,12 +121,13 @@ declare module "next/link" {
153
121
} from "react" ;
154
122
export * from "next/dist/client/link" ;
155
123
124
+ type Query = { query ?: { [ key : string ] : string | string [ ] | undefined } } ;
156
125
type StaticRoute = Exclude < Route , { query : any } > [ "pathname" ] ;
157
126
158
127
export interface LinkProps
159
128
extends Omit < NextLinkProps , "href" | "locale" > ,
160
129
AnchorHTMLAttributes < HTMLAnchorElement > {
161
- href : Route | StaticRoute | Omit < Route , "pathname" >
130
+ href : Route | StaticRoute | Query ;
162
131
locale ?: false ;
163
132
}
164
133
@@ -186,6 +155,7 @@ declare module "next/router" {
186
155
187
156
type NextTransitionOptions = NonNullable < Parameters < Router [ "push" ] > [ 2 ] > ;
188
157
type StaticRoute = Exclude < Route , { query : any } > [ "pathname" ] ;
158
+ type Query = { query ?: { [ key : string ] : string | string [ ] | undefined } } ;
189
159
190
160
interface TransitionOptions extends Omit < NextTransitionOptions , "locale" > {
191
161
locale ?: false ;
@@ -207,12 +177,12 @@ declare module "next/router" {
207
177
locale ?: Locale ;
208
178
locales ?: undefined ;
209
179
push (
210
- url : Route | StaticRoute | Omit < Route , "pathname" > ,
180
+ url : Route | StaticRoute | Query ,
211
181
as ?: string ,
212
182
options ?: TransitionOptions
213
183
) : Promise < boolean > ;
214
184
replace (
215
- url : Route | StaticRoute | Omit < Route , "pathname" > ,
185
+ url : Route | StaticRoute | Query ,
216
186
as ?: string ,
217
187
options ?: TransitionOptions
218
188
) : Promise < boolean > ;
0 commit comments