Skip to content

add tests asserting on types of that callback function receives#70

Merged
chodorowicz merged 1 commit intomainfrom
add-callback-tests
Apr 4, 2026
Merged

add tests asserting on types of that callback function receives#70
chodorowicz merged 1 commit intomainfrom
add-callback-tests

Conversation

@chodorowicz
Copy link
Copy Markdown
Owner

add a test that the asserts on existing behavior of callback functions

@chodorowicz chodorowicz merged commit 78da0bc into main Apr 4, 2026
1 check passed
@chodorowicz chodorowicz deleted the add-callback-tests branch April 4, 2026 16:25
Comment thread src/index.test-d.ts
callback: (data: Promise<number>) => {
expectType<Promise<number>>(data);
},
});
Copy link
Copy Markdown
Contributor

@urbanfly urbanfly Apr 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now the declared type of the return value will be () => Promise<Promise<number>> which is not really a valid type.

Extend it a bit:

const fn = debounce(() => Promise.resolve(42), 100, {
  callback: (data: Promise<number>) => {
    expectType<Promise<number>>(data);
  },
});

const result = await fn();
// result === 42
// the function type claims that it will be a Promise<number>, which is impossible

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I now realize that you understand the point I was making above - and I didn't get your point about the callback option. This PR, combined with #68 should be a good combo.

urbanfly added a commit to urbanfly/ts-debounce that referenced this pull request Apr 6, 2026
urbanfly added a commit to urbanfly/ts-debounce that referenced this pull request Apr 7, 2026
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 this pull request may close these issues.

2 participants