Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"del" type regarding string and array of string #1593

Open
MichielDeMey opened this issue Jun 1, 2022 · 1 comment
Open

"del" type regarding string and array of string #1593

MichielDeMey opened this issue Jun 1, 2022 · 1 comment

Comments

@MichielDeMey
Copy link

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?

@luin
Copy link
Collaborator

luin commented Jun 12, 2022

Hey @MichielDeMey 👋:

I didn't know there was such a limit. Thanks for raising this up! Seems to be an issue on TypeScript side microsoft/TypeScript#14107. I'm open to it if there is an easy way to fix it on our side.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants