1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-17 19:41:06 +03:00

change command options to work with Symbol rather then WeakSet

This commit is contained in:
leibale
2021-05-25 11:41:55 -04:00
parent 7b40258f73
commit ce0b3463af

View File

@@ -1,14 +1,14 @@
const symbol = Symbol('Command Options');
export type CommandOptions<T> = T & { export type CommandOptions<T> = T & {
options: never; readonly [symbol]: true
}; };
const set = new WeakSet(); export function commandOptions<T>(options: T): CommandOptions<T> {
(options as any)[symbol] = true;
export function commandOptions<T extends object>(options: T): CommandOptions<T> {
set.add(options);
return options as CommandOptions<T>; return options as CommandOptions<T>;
} }
export function isCommandOptions<T extends object>(options: any): options is CommandOptions<T> { export function isCommandOptions<T>(options: any): options is CommandOptions<T> {
return set.delete(options); return options && options[symbol] === true;
} }