Skip to content

Commit b97d18b

Browse files
committed
fix some types
1 parent b37038e commit b97d18b

File tree

10 files changed

+42
-34
lines changed

10 files changed

+42
-34
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,11 @@ This pattern works especially well for blocking commands—such as `BLPOP` and `
122122
```typescript
123123
import { commandOptions } from 'redis';
124124

125-
const blPopPromise = client.blPop(commandOptions({ isolated: true }), 'key', 0);
125+
const blPopPromise = client.blPop(
126+
commandOptions({ isolated: true }),
127+
'key',
128+
0
129+
);
126130

127131
await client.lPush('key', ['1', '2']);
128132

index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const modules = {
1515
ts: RedisTimeSeries
1616
};
1717

18-
export function createClient<S extends RedisScripts = Record<string, never>>(
18+
export function createClient<S extends RedisScripts>(
1919
options?: Omit<RedisClientOptions<never, S>, 'modules'>
2020
): RedisClientType<typeof modules, S> {
2121
return _createClient({
@@ -24,7 +24,7 @@ export function createClient<S extends RedisScripts = Record<string, never>>(
2424
});
2525
}
2626

27-
export function createCluster<S extends RedisScripts = Record<string, never>>(
27+
export function createCluster<S extends RedisScripts>(
2828
options: Omit<RedisClusterOptions<never, S>, 'modules'>
2929
): RedisClusterType<typeof modules, S> {
3030
return _createCluster({

packages/client/lib/client/index.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -573,8 +573,8 @@ describe('Client', () => {
573573
describe('PubSub', () => {
574574
testUtils.testWithClient('should be able to publish and subscribe to messages', async publisher => {
575575
function assertStringListener(message: string, channel: string) {
576-
assert.ok(typeof message === 'string');
577-
assert.ok(typeof channel === 'string');
576+
assert.equal(typeof message, 'string');
577+
assert.equal(typeof channel, 'string');
578578
}
579579

580580
function assertBufferListener(message: Buffer, channel: Buffer) {

packages/client/lib/client/index.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,11 @@ type ConvertArgumentType<Type, ToType> =
3434
) : (
3535
Type extends Set<infer Member> ? Set<ConvertArgumentType<Member, ToType>> : (
3636
Type extends Map<infer Key, infer Value> ? Map<Key, ConvertArgumentType<Value, ToType>> : (
37-
Type extends Record<keyof any, any> ? {
38-
[Property in keyof Type]: ConvertArgumentType<Type[Property], ToType>
39-
} : Type
37+
Type extends Array<infer Member> ? Array<ConvertArgumentType<Member, ToType>> : (
38+
Type extends Record<keyof any, any> ? {
39+
[Property in keyof Type]: ConvertArgumentType<Type[Property], ToType>
40+
} : Type
41+
)
4042
)
4143
)
4244
);
@@ -57,21 +59,23 @@ type WithCommands = {
5759
[P in keyof typeof COMMANDS]: RedisClientCommandSignature<(typeof COMMANDS)[P]>;
5860
};
5961

62+
export type ExcludeMappedString<S> = string extends S ? never : S;
63+
6064
export type WithModules<M extends RedisModules> = {
61-
[P in keyof M as M[P] extends never ? never : P]: {
62-
[C in keyof M[P]]: RedisClientCommandSignature<M[P][C]>;
65+
[P in keyof M as ExcludeMappedString<P>]: {
66+
[C in keyof M[P] as ExcludeMappedString<C>]: RedisClientCommandSignature<M[P][C]>;
6367
};
6468
};
6569

6670
export type WithScripts<S extends RedisScripts> = {
67-
[P in keyof S as S[P] extends never ? never : P]: RedisClientCommandSignature<S[P]>;
71+
[P in keyof S as ExcludeMappedString<P>]: RedisClientCommandSignature<S[P]>;
6872
};
6973

70-
export type RedisClientType<M extends RedisModules = Record<string, never>, S extends RedisScripts = Record<string, never>> =
74+
export type RedisClientType<M extends RedisModules, S extends RedisScripts> =
7175
RedisClient<M, S> & WithCommands & WithModules<M> & WithScripts<S>;
7276

7377
export type InstantiableRedisClient<M extends RedisModules, S extends RedisScripts> =
74-
new (...args: ConstructorParameters<typeof RedisClient>) => RedisClientType<M, S>;
78+
new (options?: RedisClientOptions<M, S>) => RedisClientType<M, S>;
7579

7680
export interface ClientCommandOptions extends QueueCommandOptions {
7781
isolated?: boolean;
@@ -85,7 +89,7 @@ export default class RedisClient<M extends RedisModules, S extends RedisScripts>
8589
return commandOptions(options);
8690
}
8791

88-
static extend<M extends RedisModules = Record<string, never>, S extends RedisScripts = Record<string, never>>(plugins?: RedisPlugins<M, S>): InstantiableRedisClient<M, S> {
92+
static extend<M extends RedisModules, S extends RedisScripts>(plugins?: RedisPlugins<M, S>): InstantiableRedisClient<M, S> {
8993
const Client = <any>extendWithModulesAndScripts({
9094
BaseClass: RedisClient,
9195
modules: plugins?.modules,
@@ -101,7 +105,7 @@ export default class RedisClient<M extends RedisModules, S extends RedisScripts>
101105
return Client;
102106
}
103107

104-
static create<M extends RedisModules = Record<string, never>, S extends RedisScripts = Record<string, never>>(options?: RedisClientOptions<M, S>): RedisClientType<M, S> {
108+
static create<M extends RedisModules, S extends RedisScripts>(options?: RedisClientOptions<M, S>): RedisClientType<M, S> {
105109
return new (RedisClient.extend(options))(options);
106110
}
107111

packages/client/lib/client/multi-command.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,26 @@ import COMMANDS from './commands';
22
import { RedisCommand, RedisCommandArguments, RedisCommandRawReply, RedisModules, RedisPlugins, RedisScript, RedisScripts } from '../commands';
33
import RedisMultiCommand, { RedisMultiQueuedCommand } from '../multi-command';
44
import { extendWithCommands, extendWithModulesAndScripts, LegacyCommandArguments, transformLegacyCommandArguments } from '../commander';
5+
import { ExcludeMappedString } from '.';
56

67
type RedisClientMultiCommandSignature<C extends RedisCommand, M extends RedisModules, S extends RedisScripts> =
78
(...args: Parameters<C['transformArguments']>) => RedisClientMultiCommandType<M, S>;
89

910
type WithCommands<M extends RedisModules, S extends RedisScripts> = {
10-
[P in keyof typeof COMMANDS]: RedisClientMultiCommandSignature<(typeof COMMANDS)[P], M, S>
11+
[P in keyof typeof COMMANDS]: RedisClientMultiCommandSignature<(typeof COMMANDS)[P], M, S>;
1112
};
1213

1314
type WithModules<M extends RedisModules, S extends RedisScripts> = {
14-
[P in keyof M as M[P] extends never ? never : P]: {
15-
[C in keyof M[P]]: RedisClientMultiCommandSignature<M[P][C], M, S>;
15+
[P in keyof M as ExcludeMappedString<P>]: {
16+
[C in keyof M[P] as ExcludeMappedString<C>]: RedisClientMultiCommandSignature<M[P][C], M, S>;
1617
};
1718
};
1819

1920
type WithScripts<M extends RedisModules, S extends RedisScripts> = {
20-
[P in keyof S as S[P] extends never ? never : P]: RedisClientMultiCommandSignature<S[P], M, S>
21+
[P in keyof S as ExcludeMappedString<P>]: RedisClientMultiCommandSignature<S[P], M, S>;
2122
};
2223

23-
export type RedisClientMultiCommandType<M extends RedisModules = Record<string, never>, S extends RedisScripts = Record<string, never>> =
24+
export type RedisClientMultiCommandType<M extends RedisModules, S extends RedisScripts> =
2425
RedisClientMultiCommand & WithCommands<M, S> & WithModules<M, S> & WithScripts<M, S>;
2526

2627
export type RedisClientMultiExecutor = (queue: Array<RedisMultiQueuedCommand>, chainId?: symbol) => Promise<Array<RedisCommandRawReply>>;

packages/client/lib/cluster/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ type WithCommands = {
2020
[P in keyof typeof COMMANDS]: RedisClientCommandSignature<(typeof COMMANDS)[P]>;
2121
};
2222

23-
export type RedisClusterType<M extends RedisModules = Record<string, never>, S extends RedisScripts = Record<string, never>> =
23+
export type RedisClusterType<M extends RedisModules, S extends RedisScripts> =
2424
RedisCluster<M, S> & WithCommands & WithModules<M> & WithScripts<S>;
2525

26-
export default class RedisCluster<M extends RedisModules = Record<string, never>, S extends RedisScripts = Record<string, never>> extends EventEmitter {
26+
export default class RedisCluster<M extends RedisModules, S extends RedisScripts> extends EventEmitter {
2727
static extractFirstKey(command: RedisCommand, originalArgs: Array<unknown>, redisArgs: RedisCommandArguments): RedisCommandArgument | undefined {
2828
if (command.FIRST_KEY_INDEX === undefined) {
2929
return undefined;
@@ -34,7 +34,7 @@ export default class RedisCluster<M extends RedisModules = Record<string, never>
3434
return command.FIRST_KEY_INDEX(...originalArgs);
3535
}
3636

37-
static create<M extends RedisModules = Record<string, never>, S extends RedisScripts = Record<string, never>>(options?: RedisClusterOptions<M, S>): RedisClusterType<M, S> {
37+
static create<M extends RedisModules, S extends RedisScripts>(options?: RedisClusterOptions<M, S>): RedisClusterType<M, S> {
3838
return new (<any>extendWithModulesAndScripts({
3939
BaseClass: RedisCluster,
4040
modules: options?.modules,

packages/client/lib/cluster/multi-command.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { RedisCommand, RedisCommandArgument, RedisCommandArguments, RedisCommand
33
import RedisMultiCommand, { RedisMultiQueuedCommand } from '../multi-command';
44
import { extendWithCommands, extendWithModulesAndScripts } from '../commander';
55
import RedisCluster from '.';
6+
import { ExcludeMappedString } from '../client';
67

78
type RedisClusterMultiCommandSignature<C extends RedisCommand, M extends RedisModules, S extends RedisScripts> =
89
(...args: Parameters<C['transformArguments']>) => RedisClusterMultiCommandType<M, S>;
@@ -12,16 +13,16 @@ type WithCommands<M extends RedisModules, S extends RedisScripts> = {
1213
};
1314

1415
type WithModules<M extends RedisModules, S extends RedisScripts> = {
15-
[P in keyof M as M[P] extends never ? never : P]: {
16-
[C in keyof M[P]]: RedisClusterMultiCommandSignature<M[P][C], M, S>;
16+
[P in keyof M as ExcludeMappedString<P>]: {
17+
[C in keyof M[P] as ExcludeMappedString<C>]: RedisClusterMultiCommandSignature<M[P][C], M, S>;
1718
};
1819
};
1920

2021
type WithScripts<M extends RedisModules, S extends RedisScripts> = {
21-
[P in keyof S as S[P] extends never ? never : P]: RedisClusterMultiCommandSignature<S[P], M, S>
22+
[P in keyof S as ExcludeMappedString<P>]: RedisClusterMultiCommandSignature<S[P], M, S>
2223
};
2324

24-
export type RedisClusterMultiCommandType<M extends RedisModules = Record<string, never>, S extends RedisScripts = Record<string, never>> =
25+
export type RedisClusterMultiCommandType<M extends RedisModules, S extends RedisScripts> =
2526
RedisClusterMultiCommand & WithCommands<M, S> & WithModules<M, S> & WithScripts<M, S>;
2627

2728
export type RedisClusterMultiExecutor = (queue: Array<RedisMultiQueuedCommand>, firstKey?: RedisCommandArgument, chainId?: symbol) => Promise<Array<RedisCommandRawReply>>;

packages/client/lib/command-options.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ export function commandOptions<T>(options: T): CommandOptions<T> {
1010
}
1111

1212
export function isCommandOptions<T>(options: any): options is CommandOptions<T> {
13-
return options && options[symbol] === true;
13+
return options?.[symbol] === true;
1414
}

packages/client/lib/commander.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export function extendWithModulesAndScripts<T extends Instantiable>(config: Exte
7070
return (Commander ?? config.BaseClass) as any;
7171
}
7272

73-
export function transformCommandArguments<T = unknown>(
73+
export function transformCommandArguments<T>(
7474
command: RedisCommand,
7575
args: Array<unknown>
7676
): {

packages/test-utils/lib/index.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@ import { RedisServerDockerConfig, spawnRedisServer, spawnRedisCluster } from './
55
import yargs from 'yargs';
66
import { hideBin } from 'yargs/helpers';
77

8-
interface TestUtilsConfig<M extends RedisModules, S extends RedisScripts> {
8+
interface TestUtilsConfig {
99
dockerImageName: string;
1010
dockerImageVersionArgument: string;
1111
defaultDockerVersion: string;
12-
defaultClientOptions?: Partial<RedisClientOptions<M, S>>;
13-
defaultClusterOptions?: Partial<RedisClusterOptions<M, S>>;
1412
}
1513

1614
interface CommonTestOptions {
@@ -29,7 +27,7 @@ interface ClusterTestOptions<M extends RedisModules, S extends RedisScripts> ext
2927
numberOfNodes?: number;
3028
}
3129

32-
export default class TestUtils<M extends RedisModules, S extends RedisScripts> {
30+
export default class TestUtils {
3331
static #getVersion(argumentName: string, defaultVersion: string): Array<number> {
3432
return yargs(hideBin(process.argv))
3533
.option(argumentName, {
@@ -52,7 +50,7 @@ export default class TestUtils<M extends RedisModules, S extends RedisScripts> {
5250

5351
readonly #DOCKER_IMAGE: RedisServerDockerConfig;
5452

55-
constructor(config: TestUtilsConfig<M, S>) {
53+
constructor(config: TestUtilsConfig) {
5654
this.#DOCKER_IMAGE = {
5755
image: config.dockerImageName,
5856
version: TestUtils.#getVersion(config.dockerImageVersionArgument, config.defaultDockerVersion)

0 commit comments

Comments
 (0)