Skip to content

Commit

Permalink
fix(type): set missing key expect error
Browse files Browse the repository at this point in the history
  • Loading branch information
Gehbt committed Feb 10, 2024
1 parent 49b5136 commit 219259b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
5 changes: 1 addition & 4 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ declare module "fastify" {
}

type FastifySecureSession = FastifyPluginCallback<fastifySecureSession.SecureSessionPluginOptions | (fastifySecureSession.SecureSessionPluginOptions & Required<Pick<fastifySecureSession.SecureSessionPluginOptions, 'sessionName'>>)[]>;
interface SessionData {}

declare namespace fastifySecureSession {
export type Session<T = SessionData> = Partial<T> & {
Expand All @@ -29,10 +30,6 @@ declare namespace fastifySecureSession {
touch(): void;
}

export interface SessionData {
[key: string]: any;
}

export type SecureSessionPluginOptions = {
cookie?: CookieSerializeOptions
cookieName?: string
Expand Down
3 changes: 3 additions & 0 deletions types/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,13 @@ app.get("/not-websockets", async (request, reply) => {
expectType<FastifyRequest>(request);
expectType<FastifyReply>(reply);
expectType<Session>(request.session);
// @ts-expect-error undefined key
request.session.set("baz", "bar");
request.session.set("foo", "bar");
expectType<string | undefined>(request.session.get("foo"));
expectType<any>(request.session.get("baz"));
expectType<string | undefined>(request.session.foo);
// @ts-expect-error undefined key
expectType<any>(request.session.baz);
expectType<SessionData | undefined>(request.session.data());
request.session.delete();
Expand Down

0 comments on commit 219259b

Please sign in to comment.