Skip to content

Commit

Permalink
refactor(websockets): improve type safety for WebSocketGateway options
Browse files Browse the repository at this point in the history
  • Loading branch information
sapenlei committed Dec 10, 2024
1 parent d7555a5 commit 296e9f5
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions packages/websockets/decorators/socket-gateway.decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@ import { GatewayMetadata } from '../interfaces';
* @publicApi
*/
export function WebSocketGateway(port?: number): ClassDecorator;
export function WebSocketGateway<
T extends Record<string, any> = GatewayMetadata,
>(options?: T): ClassDecorator;
export function WebSocketGateway<
T extends Record<string, any> = GatewayMetadata,
>(port?: number, options?: T): ClassDecorator;
export function WebSocketGateway<
T extends Record<string, any> = GatewayMetadata,
>(portOrOptions?: number | T, options?: T): ClassDecorator {
export function WebSocketGateway<T extends GatewayMetadata>(
options?: T,
): ClassDecorator;
export function WebSocketGateway<T extends GatewayMetadata>(
port?: number,
options?: T,
): ClassDecorator;
export function WebSocketGateway<T extends GatewayMetadata>(
portOrOptions?: number | T,
options?: T,
): ClassDecorator {
const isPortInt = Number.isInteger(portOrOptions as number);
// eslint-disable-next-line prefer-const
let [port, opt] = isPortInt ? [portOrOptions, options] : [0, portOrOptions];
Expand Down

0 comments on commit 296e9f5

Please sign in to comment.