Skip to content

Commit

Permalink
fix: ApiOptions intellisense (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssukienn committed Mar 26, 2024
1 parent 5f33848 commit 30a5448
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
17 changes: 15 additions & 2 deletions lib/api-specification.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@ const bindTrailArgs = (fn: Function, ...bound_args: any[]) => {
};
};

import { ApiExtraModels, ApiOperation, ApiResponse } from "@nestjs/swagger";
import { ApiSpecification } from "./api-specification";
import {
ApiExtraModels,
ApiOperation,
ApiQueryOptions,
ApiResponse,
} from "@nestjs/swagger";
import { ApiOptions, ApiSpecification } from "./api-specification";

// Mock specific decorator factory to return their params instead of decorator itself
jest.mock("@nestjs/swagger", () => ({
Expand Down Expand Up @@ -323,3 +328,11 @@ describe("ApiSpecification", () => {
});
});
});

describe("ApiOptions", () => {
it("intellisense should work", () => {
const options: ApiOptions = {
apiQueryOptions: (apiDecorator) => [],
};
});
});
6 changes: 3 additions & 3 deletions lib/api-specification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,10 @@ type ApiDecoratorFactories = {
: never]: NestJsSwaggerMethods[K];
};

type OrderSuffix = `${number}` | "";

export type ApiOptions = {
[K in keyof ApiDecoratorFactories as `${Uncapitalize<K>}Options${string}`]?: (
[K in keyof ApiDecoratorFactories as `${Uncapitalize<K>}Options${
| number
| ""}`]?: (
apiDecorator: ApiDecoratorFactories[K] & { brand: K },
) =>
| ReturnType<ApiDecoratorFactories[K] & { brand: K }>
Expand Down

0 comments on commit 30a5448

Please sign in to comment.