"del" type regarding string and array of string
Consider a function to remove a single key/array of keys:
public async removeKeys(keys: string | string[]): Promise<void> {
this.redis.del(keys);
}
This currently gives a type error on the .del function since it cannot accept a union of string or string[].
I would expect that there is no type error since the code above simply works. Either passing a single key or an array of keys gives the correct result.
The current workaround is forcing the string to be an array, but that's weird to cast here just for typing.
public async removeKeys(keys: string | string[]): Promise<void> {
keys = Array.isArray(userIds) ? userIds : [userIds]; // Needs explicit conversion here
this.redis.del(keys);
}
What do you think? Is this the intended behavior or could we loosen/improve the typing here?
Hey @MichielDeMey 👋:
I didn't know there was such a limit. Thanks for raising this up! Seems to be an issue on TypeScript side https://github.com/microsoft/TypeScript/issues/14107. I'm open to it if there is an easy way to fix it on our side.