Skip to content

Commit

Permalink
feat(ts): Add types and ts documentation
Browse files Browse the repository at this point in the history
Signed-off-by: Roberto Bianchi <[email protected]>
  • Loading branch information
rozzilla committed Apr 21, 2024
1 parent 1838e99 commit 375a232
Show file tree
Hide file tree
Showing 4 changed files with 6,427 additions and 3 deletions.
14 changes: 14 additions & 0 deletions index.d.ts
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;
36 changes: 36 additions & 0 deletions index.test-d.ts
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>({});
Loading

0 comments on commit 375a232

Please sign in to comment.