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

fix: support typing overloaded functions #1

Merged
merged 2 commits into from
May 22, 2023
Merged

Conversation

mcous
Copy link
Owner

@mcous mcous commented May 22, 2023

Overview

TypeScript's built in Parameters and ReturnType utilities do not understand overloaded functions. This makes stubbing overloaded functions quite difficult with vitest-when, because calledWith, thenReturn, et. al. will get typed to accept the last overload rather than a union of all overloads.

This PR adds improves the typing for overloaded functions in two ways:

  • calledWith will accept a union of all overloaded arguments
  • thenReturn/thenResolve will accept the specific return type given the arguments used in calledWith

Change log

  • Add typing support for overloaded functions
  • Add typing tests to make sure we support vanilla vi.fn(), untyped functions, non-overloaded functions, and overloaded functions
  • Improve the README

@mcous mcous merged commit 616e8da into main May 22, 2023
@mcous mcous deleted the typescript-overload branch May 22, 2023 20:33
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.

1 participant