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

feat: add Promisify type definition #3420

Merged
merged 1 commit into from Oct 7, 2023
Merged

feat: add Promisify type definition #3420

merged 1 commit into from Oct 7, 2023

Conversation

Alfred-Skyblue
Copy link
Member

@Alfred-Skyblue Alfred-Skyblue commented Sep 22, 2023

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.
⚠️ Slowing down new functions

Warning: Slowing down new functions

As the VueUse audience continues to grow, we have been inundated with an overwhelming number of feature requests and pull requests. As a result, maintaining the project has become increasingly challenging and has stretched our capacity to its limits. As such, in the near future, we may need to slow down our acceptance of new features and prioritize the stability and quality of existing functions. Please note that new features for VueUse may not be accepted at this time. If you have any new ideas, we suggest that you first incorporate them into your own codebase, iterate on them to suit your needs, and assess their generalizability. If you strongly believe that your ideas are beneficial to the community, you may submit a pull request along with your use cases, and we would be happy to review and discuss them. Thank you for your understanding.


Description

fixed #3419

In PR #3419, when PromisifyFn received an async function, the return value was inferred as Promise<Promise<T>>, causing a type error. In this PR, we added the Promisify type to address this issue.

Additional context


🤖 Generated by Copilot at a4e30b9

Improved the type and value handling of async filters and functions in createFilterWrapper and FunctionWrapper. Added Awaited and Promisify types in ./types for compatibility with older TypeScript versions.

🤖 Generated by Copilot at a4e30b9

  • Import and define Awaited and Promisify types in types.ts to handle values that may be promises (link)
  • Use Promisify type in FunctionWrapper type in filters.ts to return the same type as the wrapped function (link)
  • Use Awaited type in createFilterWrapper function in filters.ts to resolve or reject the promise with the same value as the wrapped function (link)
  • Import Awaited and Promisify types from types.ts in filters.ts to use them in FunctionWrapper and createFilterWrapper (link)

/**
* Compatible with versions below TypeScript 4.5 Awaited
*/
export type Awaited<T> =
Copy link
Member

Choose a reason for hiding this comment

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

A suppose Awaited is builtin in TypeScript isn't it?

Copy link
Member Author

Choose a reason for hiding this comment

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

Awaited was introduced in TypeScript 4.5, here to consider compatibility.

@antfu antfu merged commit b067b8e into vueuse:main Oct 7, 2023
5 checks passed
@Alfred-Skyblue Alfred-Skyblue deleted the type-PromisifyFn branch October 7, 2023 08:04
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.

useDebounceFn with an async callback return value. useDebounceFun.then type is wrong.
2 participants