Почему типы запросов в функции handler несовместимы. Я предполагаю, что Request и ApiServerRequest, которые расширяют Request, совместимы, почему бы и нет?
const app = {}
type App = typeof app
const testRoute = {
method: 'GET',
path: '',
options: {
tags: ['api'],
description: '',
},
handler (request: ApiServerRequest<App>, reply: ResponseToolkit): ResponseObject {
return reply.view('landing', {
customerLandingHash: request.params.customerWalletPassId
})
}
}
Компиляция Typescript вызывает ошибку
Код
import {
Server,
ServerOptions,
Lifecycle,
ServerRoute,
RouteOptions,
ResponseToolkit,
ResponseObject
} from '@hapi/hapi'
export class ApiServer<A> extends Server {
app: A = {} as A
constructor (options: ServerOptions, app: A) {
super(options)
this.app = app
return this
}
route (route: ApiServerRoute<A> | Array<ApiServerRoute<A>>): void {
super.route(route)
}
}
export interface ApiServerRequest<A> extends Request {
server: ApiServer<A>
}
export interface ApiServerRequestHandler<A> extends Lifecycle.Method {
(request: ApiServerRequest<A>, reply: ResponseToolkit, err?: Error): Lifecycle.ReturnValue
}
export interface ApiServerRoute<A> extends ServerRoute {
handler: ApiServerRequestHandler<A>,
options: ApiServerRouteOptions<A>
}
export interface ApiServerRouteOptions<A> extends RouteOptions {
tags: ['api'] | ['api', string]
description: string,
handler?: ApiServerRequestHandler<A>
}