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

useAsync should return not undefined state.result if initialValue is set #134

Closed
nikolay-borzov opened this issue Jun 16, 2021 · 2 comments
Assignees
Labels
🪲 bug Something isn't working released

Comments

@nikolay-borzov
Copy link

Prior Issues

None

What is the current behavior?

state.result returned from useAsync with initialValue set has type Result | undefined. But JSDoc says

Value that will be set on initialisation, before the async function is executed.

I'd expect useAsync handle initialValue as useState does. Look at typings:

function useState<S>(initialState: S | (() => S)): [S, Dispatch<SetStateAction<S>>];
function useState<S = undefined>(): [S | undefined, Dispatch<SetStateAction<S | undefined>>];

Steps to Reproduce

const [{ result: initialData }] = useAsync(
  myAsyncFunction,
  [paramA],
  {
    initialValue: "RESULT",
  },
);

// Has type "string" | undefined
initialData 

What is the expected behavior?

initialData should have type "string"

Environment Details

  • @react-hookz/web version: 2.2.0
  • react version: 16.14.0
  • react-dom version: 16.14.0
  • typescript version: 4.3.2
  • OS: Windows
  • Browser: Chrome
  • Did this work in previous versions? Unknown
@nikolay-borzov nikolay-borzov added the 🪲 bug Something isn't working label Jun 16, 2021
@xobotyi xobotyi self-assigned this Jun 16, 2021
@xobotyi
Copy link
Contributor

xobotyi commented Jun 16, 2021

useState is way easier to type that way, but nevertheless i'll fix today

xobotyi added a commit that referenced this issue Jun 16, 2021
`useAsync` return state now properly handles presence of `initialState`
option.

resolves #134
github-actions bot pushed a commit that referenced this issue Jun 16, 2021
## [3.0.1](v3.0.0...v3.0.1) (2021-06-16)

### Bug Fixes

* improve `useAsync` typings ([#135](#135)) ([73b42ff](73b42ff)), closes [#134](#134)
@xobotyi
Copy link
Contributor

xobotyi commented Jun 16, 2021

🎉 This issue has been resolved in version 3.0.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🪲 bug Something isn't working released
Development

No branches or pull requests

2 participants