typesafe-hapi
typesafe-hapi is a fork of hapi which aims to improve typesafety. More precisely, this is a fork of @types/hapi__hapi because it has just redefined the essential APIs of hapi.
typesafe-hapi currently matches the API of hapi 18.3.x. It was tested with TypeScript 3.4.5.
How it works
typesafe-hapi
uses typesafe-joi
to infer correct type from Joi schemas automatically. It uses possesed type information to typecheck:
- request.query
- request.payload
- request.params
- response
Example
; ; ; ; server.route;
Neat, huh? See more examples in index.test-d.ts.
Usage
Import and use hapi from typesafe-hapi
:
In order to avoid any compatibility issues, and to be able to use existing packages and plugins easily, you should create an alias for typesafe-hapi
and rename it to just hapi
. In your tsconfig.json
: