Skip to content

Commit 87b03a3

Browse files
committed
Allow to typehint props on Client Side visits
1 parent 9c133b8 commit 87b03a3

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

packages/core/src/router.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -284,18 +284,19 @@ export class Router {
284284
return currentPage.resolve(component)
285285
}
286286

287-
public replace(params: ClientSideVisitOptions): void {
287+
public replace<TProps = Page['props']>(params: ClientSideVisitOptions<TProps>): void {
288288
this.clientVisit(params, { replace: true })
289289
}
290290

291-
public push(params: ClientSideVisitOptions): void {
291+
public push<TProps = Page['props']>(params: ClientSideVisitOptions<TProps>): void {
292292
this.clientVisit(params)
293293
}
294294

295-
protected clientVisit(params: ClientSideVisitOptions, { replace = false }: { replace?: boolean } = {}): void {
295+
protected clientVisit<TProps = Page['props']>(params: ClientSideVisitOptions<TProps>, { replace = false }: { replace?: boolean } = {}): void {
296296
const current = currentPage.get()
297297

298-
const props = typeof params.props === 'function' ? params.props(current.props) : (params.props ?? current.props)
298+
const props =
299+
typeof params.props === 'function' ? params.props(current.props as TProps) : (params.props ?? current.props)
299300

300301
const { onError, onFinish, onSuccess, ...pageParams } = params
301302

packages/core/src/types.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,17 +127,17 @@ export type ScrollRegion = {
127127
left: number
128128
}
129129

130-
export interface ClientSideVisitOptions {
130+
export interface ClientSideVisitOptions<TProps = Page['props']> {
131131
component?: Page['component']
132132
url?: Page['url']
133-
props?: ((props: Page['props']) => PageProps) | PageProps
133+
props?: ((props: TProps) => PageProps) | PageProps
134134
clearHistory?: Page['clearHistory']
135135
encryptHistory?: Page['encryptHistory']
136136
preserveScroll?: VisitOptions['preserveScroll']
137137
preserveState?: VisitOptions['preserveState']
138138
errorBag?: string | null
139139
onError?: (errors: Errors) => void
140-
onFinish?: (visit: ClientSideVisitOptions) => void
140+
onFinish?: (visit: ClientSideVisitOptions<TProps>) => void
141141
onSuccess?: (page: Page) => void
142142
}
143143

0 commit comments

Comments
 (0)