diff --git a/packages/client/lib/client/index.ts b/packages/client/lib/client/index.ts index b4bf49fc7bc..c400bba0f8f 100644 --- a/packages/client/lib/client/index.ts +++ b/packages/client/lib/client/index.ts @@ -1,5 +1,5 @@ import COMMANDS from './commands'; -import { RedisCommand, RedisCommandArguments, RedisCommandRawReply, RedisCommandReply, RedisFunctions, RedisModules, RedisExtensions, RedisScript, RedisScripts, RedisCommandSignature, ConvertArgumentType, RedisFunction, ExcludeMappedString, RedisCommands } from '../commands'; +import { RedisCommand, RedisCommandArguments, RedisCommandRawReply, RedisCommandReply, RedisFunctions, RedisModules, RedisExtensions, RedisScript, RedisScripts, ConvertArgumentType, RedisFunction, ExcludeMappedString, RedisCommands, RedisCommandsSignatures } from '../commands'; import RedisSocket, { RedisSocketOptions, RedisTlsSocketOptions } from './socket'; import RedisCommandsQueue, { QueueCommandOptions } from './commands-queue'; import RedisClientMultiCommand, { RedisClientMultiCommandType } from './multi-command'; @@ -15,7 +15,6 @@ import { ClientClosedError, ClientOfflineError, DisconnectsClientError } from '. import { URL } from 'url'; import { TcpSocketConnectOpts } from 'net'; import { PubSubType, PubSubListener, PubSubTypeListeners, ChannelListeners } from './pub-sub'; -import { callbackify } from 'util'; export interface RedisClientOptions< M extends RedisModules = RedisModules, @@ -69,25 +68,17 @@ export interface RedisClientOptions< pingInterval?: number; } -type WithCommands = { - [P in keyof typeof COMMANDS]: RedisCommandSignature<(typeof COMMANDS)[P]>; -}; +type WithCommands = RedisCommandsSignatures; export type WithModules = { - [P in keyof M as ExcludeMappedString

]: { - [C in keyof M[P] as ExcludeMappedString]: RedisCommandSignature; - }; + [P in keyof M as ExcludeMappedString

]: RedisCommandsSignatures; }; export type WithFunctions = { - [P in keyof F as ExcludeMappedString

]: { - [FF in keyof F[P] as ExcludeMappedString]: RedisCommandSignature; - }; + [P in keyof F as ExcludeMappedString

]: RedisCommandsSignatures; }; -export type WithScripts = { - [P in keyof S as ExcludeMappedString

]: RedisCommandSignature; -}; +export type WithScripts = RedisCommandsSignatures; export type RedisClientType< M extends RedisModules = Record, diff --git a/packages/client/lib/cluster/index.ts b/packages/client/lib/cluster/index.ts index 818930c8c82..af6bb5ac20b 100644 --- a/packages/client/lib/cluster/index.ts +++ b/packages/client/lib/cluster/index.ts @@ -1,5 +1,5 @@ import COMMANDS from './commands'; -import { RedisCommand, RedisCommandArgument, RedisCommandArguments, RedisCommandRawReply, RedisCommandReply, RedisFunctions, RedisModules, RedisExtensions, RedisScript, RedisScripts, RedisCommandSignature, RedisFunction } from '../commands'; +import { RedisCommand, RedisCommandArgument, RedisCommandArguments, RedisCommandRawReply, RedisCommandReply, RedisFunctions, RedisModules, RedisExtensions, RedisScript, RedisScripts, RedisFunction, RedisCommandsSignatures } from '../commands'; import { ClientCommandOptions, RedisClientOptions, RedisClientType, WithFunctions, WithModules, WithScripts } from '../client'; import RedisClusterSlots, { NodeAddressMap, ShardNode } from './cluster-slots'; import { attachExtensions, transformCommandReply, attachCommands, transformCommandArguments } from '../commander'; @@ -50,9 +50,7 @@ export interface RedisClusterOptions< nodeAddressMap?: NodeAddressMap; } -type WithCommands = { - [P in keyof typeof COMMANDS]: RedisCommandSignature<(typeof COMMANDS)[P]>; -}; +type WithCommands = RedisCommandsSignatures; export type RedisClusterType< M extends RedisModules = Record, diff --git a/packages/client/lib/commands/index.ts b/packages/client/lib/commands/index.ts index 60f9720c8d1..aecee46e7e7 100644 --- a/packages/client/lib/commands/index.ts +++ b/packages/client/lib/commands/index.ts @@ -36,17 +36,27 @@ export type ConvertArgumentType = ) ); -export type RedisCommandSignature< - Command extends RedisCommand, - Params extends Array = Parameters -> = >( - ...args: Params | [options: Options, ...rest: Params] -) => Promise< - ConvertArgumentType< - RedisCommandReply, - Options['returnBuffers'] extends true ? Buffer : string - > ->; +// using "Call Signatures" (https://www.typescriptlang.org/docs/handbook/2/functions.html#call-signatures) and not a union for better types in WebStorm +export type Command< + FN extends (...args: Array) => any +> = { + (...args: Parameters): Promise, string>>; + >( + options: Options, + ...rest: Parameters + ): Promise< + ConvertArgumentType< + ReturnType, + Options['returnBuffers'] extends true ? Buffer : string + > + >; +}; + +export type RedisCommandsSignatures> = { + [P in keyof T as ExcludeMappedString

]: Command< + (...args: Parameters) => RedisCommandReply + >; +}; export interface RedisCommands { [command: string]: RedisCommand;