-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ts): Add types and ts documentation
Signed-off-by: Roberto Bianchi <[email protected]>
- Loading branch information
Showing
4 changed files
with
6,427 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import fastify, { | ||
type FastifyBaseLogger, | ||
type FastifyReply, | ||
type FastifyRequest, | ||
} from "fastify"; | ||
|
||
declare namespace fastifyasyncforge { | ||
export const app: typeof fastify; | ||
export const request: FastifyRequest; | ||
export const reply: FastifyReply; | ||
export const logger: FastifyBaseLogger; | ||
} | ||
|
||
export = fastifyasyncforge; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { expectAssignable, expectError, expectType } from "tsd"; | ||
import { app, logger, reply, request } from "."; | ||
import fastify, { | ||
type FastifyInstance, | ||
type FastifyBaseLogger, | ||
type FastifyRequest, | ||
type FastifyReply, | ||
} from "fastify"; | ||
|
||
const fastifyInstance = fastify(); | ||
const appInstance = app(); | ||
|
||
// app | ||
expectAssignable<FastifyInstance>(fastifyInstance); | ||
expectAssignable<FastifyInstance>(appInstance); | ||
expectError<FastifyInstance>({}); | ||
|
||
// request | ||
expectType<FastifyRequest>(request); | ||
expectType<unknown>(request.body); | ||
expectType<boolean>(request.is404); | ||
expectError<FastifyRequest>({}); | ||
|
||
// reply | ||
expectType<FastifyReply>(reply); | ||
expectType<number>(reply.statusCode); | ||
expectType<boolean>(reply.sent); | ||
expectError<FastifyReply>({}); | ||
|
||
// logger | ||
expectType<FastifyBaseLogger>(fastifyInstance.log); | ||
expectType<FastifyBaseLogger>(logger); | ||
expectType<void>(logger.debug({ msg: "hey" })); | ||
expectType<void>(logger.info({ msg: "oh!" })); | ||
expectType<void>(logger.warn({ msg: "let's go!!!" })); | ||
expectError<FastifyBaseLogger>({}); |
Oops, something went wrong.