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

Deno KV .listenQueue() should have different types #21780

Closed
kitsonk opened this issue Jan 3, 2024 · 0 comments · Fixed by #21781
Closed

Deno KV .listenQueue() should have different types #21780

kitsonk opened this issue Jan 3, 2024 · 0 comments · Fixed by #21781

Comments

@kitsonk
Copy link
Contributor

kitsonk commented Jan 3, 2024

Version: Deno 1.39.1

Currently .listenQueue() is typed as the following:

    listenQueue(
      handler: (value: unknown) => Promise<void> | void,
    ): Promise<void>;

The problem is that when consuming the API, unknown becomes very restrictive. For example if you were to do something like this:

interface MyEvent {
  type: string;
}

const db = await Deno.openKv();
db.listenQueue((value: MyEvent) => {});

You would get the following error:

Argument of type '(value: MyEvent) => void' is not assignable to parameter of type '(value: unknown) => void | Promise<void>'.
  Types of parameters 'value' and 'value' are incompatible.
    Type 'unknown' is not assignable to type 'MyEvent'.

Which makes usage quite user hostile. For consumption of APIs where the value could be anything, it is better to use the top type any, which is what occurs in several instances in built in types where the value could be of any type.

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

Successfully merging a pull request may close this issue.

1 participant