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
[Typings] improve userEvent.type typings to only return a Promise when using delay is set #480
Comments
oh lol delay is a number, not a boolean. My bad 😆 I guess it still applies the same idea edit: I updated the PR details and title to reflect it is a number and not a boolean |
@laquasicinque As clever as |
I have committed @ljosberinn's types from #480 (comment) and added tests in #491. |
Thanks, it looks great! 🚀 |
userEvent.type
always returns a promise, but we only need to await it if we're using the{ delay: number }
as the third argument, according to the docsIn js that's fine, but in TS, the compiler or eslint might warn you about having floating promises.
that could force the TS users to always use
await
even though it might not be necessary - it's different from js where we could just not await it.A possible solution could be to use type overloading when defining the function
type
, so it returnsPromise<void>
if{ delay: number }
is passed, but no value is provided, returnvoid
I think that could be achieved with the following code
That should allow the inference to work
skipping options
not passing delay
using
delay: number
(which gives us the Promise as expected)While this works, I wanted to read your thoughts as the code does return a Promise (instead of void), just that it is not required to be awaited, so it could be misleading, or perhaps it's not worth the effort. I could do the PR as it is just as simple as updating the typings with that option.
The text was updated successfully, but these errors were encountered: