Skip to content

Commit

Permalink
types(index): allow undefined for some optional properties (#209)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fdawgs authored Jan 28, 2025
1 parent 2d63d88 commit aceaa25
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
6 changes: 3 additions & 3 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ type FastifyBearerAuth = FastifyPluginCallback<fastifyBearerAuth.FastifyBearerAu
declare namespace fastifyBearerAuth {
export interface FastifyBearerAuthOptions {
keys: Set<string> | string[];
auth?: (key: string, req: FastifyRequest) => boolean | Promise<boolean>;
auth?: (key: string, req: FastifyRequest) => boolean | Promise<boolean> | undefined;
errorResponse?: (err: Error) => { error: string };
contentType?: string;
contentType?: string | undefined;
bearerType?: string;
specCompliance?: 'rfc6749' | 'rfc6750';
addHook?: boolean;
addHook?: boolean | undefined;
verifyErrorLogLevel?: string;
}

Expand Down
36 changes: 27 additions & 9 deletions types/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,36 +27,54 @@ const pluginOptionsKeyArray: FastifyBearerAuthOptions = {
bearerType: ''
}

const pluginOptionsUndefined: FastifyBearerAuthOptions = {
keys: ['foo'],
auth: undefined,
errorResponse: (err: Error) => { return { error: err.message } },
contentType: undefined,
bearerType: undefined,
addHook: undefined
}

expectAssignable<{
keys: Set<string> | string[];
auth?: (key: string, req: FastifyRequest) => boolean | Promise<boolean>;
auth?: (key: string, req: FastifyRequest) => boolean | Promise<boolean> | undefined;
errorResponse?: (err: Error) => { error: string };
contentType?: string;
contentType?: string | undefined;
bearerType?: string;
}>(pluginOptions)

expectAssignable<{
keys: Set<string> | string[];
auth?: (key: string, req: FastifyRequest) => boolean | Promise<boolean>;
auth?: (key: string, req: FastifyRequest) => boolean | Promise<boolean> | undefined;
errorResponse?: (err: Error) => { error: string };
contentType?: string;
contentType?: string | undefined;
bearerType?: string;
addHook?: boolean;
addHook?: boolean | undefined;
}>(pluginOptionsKeyArray)

expectAssignable<{
keys: Set<string> | string[];
auth?: (key: string, req: FastifyRequest) => boolean | Promise<boolean>;
auth?: (key: string, req: FastifyRequest) => boolean | Promise<boolean> | undefined;
errorResponse?: (err: Error) => { error: string };
contentType?: string | undefined;
bearerType?: string;
addHook?: boolean | undefined;
}>(pluginOptionsUndefined)

expectAssignable<{
keys: Set<string> | string[];
auth?: (key: string, req: FastifyRequest) => boolean | Promise<boolean> | undefined;
errorResponse?: (err: Error) => { error: string };
contentType?: string;
contentType?: string | undefined;
bearerType?: string;
}>(pluginOptionsAuthPromise)

expectAssignable<{
keys: Set<string> | string[];
auth?: (key: string, req: FastifyRequest) => boolean | Promise<boolean>;
auth?: (key: string, req: FastifyRequest) => boolean | Promise<boolean> | undefined;
errorResponse?: (err: Error) => { error: string };
contentType?: string;
contentType?: string | undefined;
bearerType?: string;
specCompliance?: 'rfc6749' | 'rfc6750';
verifyErrorLogLevel?: string;
Expand Down

0 comments on commit aceaa25

Please sign in to comment.