Skip to content

fix(useRequest): infer data type from services that return a promise chain - #2966

Open
jamalkamaladdin wants to merge 1 commit into
alibaba:masterfrom
jamalkamaladdin:fix/2965-userequest-then-inference
Open

jamalkamaladdin wants to merge 1 commit into
alibaba:masterfrom
jamalkamaladdin:fix/2965-userequest-then-inference

Conversation

@jamalkamaladdin

Copy link
Copy Markdown

🤔 This is a ...

  • New feature
  • Bug fix
  • Site / documentation update
  • Demo update
  • TypeScript definition update
  • Bundle size optimization
  • Performance optimization
  • Enhancement feature
  • Internationalization
  • Refactoring
  • Code style optimization
  • Test Case
  • Branch merge
  • Other (about what?)

🔗 Related issue link

Fixes #2965.

💡 Background and solution

useRequest.ts: first overload constrains TService to a function returning any, and its service parameter has type TService & AnyService.
useRequest(() => Promise.resolve(1).then((x) => x)) gives data as number, not any.
A service returning a non-promise fails to compile.
index.spec.ts: type and runtime case for a service returning a promise chain.

📝 Changelog

English: useRequest infers data from a service returning promise.then(...).

☑️ Self Check before Merge

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • TypeScript definition is updated/provided or not needed
  • Changelog is provided or not needed

This branch has not been deployed

No deployments
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.

[useRequest] 3.10.0 typing regression:service 直接返回 promise.then(...) 时 data 被推断为 any

1 participant