-
-
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.
Merge pull request #1 from rozzilla/feat/ts/add-types-and-ts-document…
…ation feat(ts): Add types and ts documentation
- Loading branch information
Showing
4 changed files
with
6,438 additions
and
4 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,15 @@ | ||
import { | ||
type FastifyInstance, | ||
type FastifyBaseLogger, | ||
type FastifyReply, | ||
type FastifyRequest, | ||
} from "fastify"; | ||
|
||
declare namespace fastifyasyncforge { | ||
export function app<T extends FastifyInstance>(): T; | ||
export function request<T extends FastifyRequest>(): T; | ||
export function reply<T extends FastifyReply>(): T; | ||
export function logger<T extends FastifyBaseLogger>(): T; | ||
} | ||
|
||
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,45 @@ | ||
import { expectAssignable, expectError, expectType } from "tsd"; | ||
import { app, logger, reply, request } from "."; | ||
import fastify, { | ||
type FastifyInstance, | ||
type FastifyBaseLogger, | ||
type FastifyRequest, | ||
type FastifyReply, | ||
type RawServerDefault, | ||
type RouteGenericInterface, | ||
} from "fastify"; | ||
|
||
const fastifyInstance = fastify(); | ||
|
||
// app | ||
expectAssignable<FastifyInstance>(fastifyInstance); | ||
expectAssignable<FastifyInstance>(app()); | ||
expectAssignable<FastifyInstance>(app<FastifyInstance<RawServerDefault>>()); | ||
expectError<FastifyInstance>(app<string>()); | ||
expectError<FastifyInstance>({}); | ||
|
||
// request | ||
expectType<FastifyRequest>(request()); | ||
expectType<FastifyRequest>(request<FastifyRequest<RouteGenericInterface>>()); | ||
expectError<FastifyRequest>(request<boolean>()); | ||
expectType<unknown>(request().body); | ||
expectType<boolean>(request().is404); | ||
expectError<FastifyRequest>({}); | ||
|
||
// reply | ||
expectType<FastifyReply>(reply()); | ||
expectType<FastifyReply>(reply<FastifyReply<RawServerDefault>>()); | ||
expectType<number>(reply().statusCode); | ||
expectType<boolean>(reply().sent); | ||
expectError<FastifyReply>(reply<number>()); | ||
expectError<FastifyReply>({}); | ||
|
||
// logger | ||
expectType<FastifyBaseLogger>(fastifyInstance.log); | ||
expectType<FastifyBaseLogger>(logger()); | ||
expectType<FastifyBaseLogger>(logger<FastifyBaseLogger>()); | ||
expectType<void>(logger().debug({ msg: "hey" })); | ||
expectType<void>(logger().info({ msg: "oh!" })); | ||
expectType<void>(logger().warn({ msg: "let's go!!!" })); | ||
expectError<FastifyBaseLogger>(logger<object>()); | ||
expectError<FastifyBaseLogger>({}); |
Oops, something went wrong.