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

Improve doc clarity around TypeScript and createAsyncThunk usage #4523

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

EvHaus
Copy link

@EvHaus EvHaus commented Jul 21, 2024

I had a difficult time figuring out how to get proper TypeScript responses for dispatched thunk actions. I read the docs several times, and even though the answer was there (use type narrowing via match), I missed it each time.

I think I skipped it because the relevant information was nested under the "Manually defining thunkAPI types" category, which I wasn't doing in my case.

Since this type narrowing is very useful and relevant even when you're not manually typing thunkAPI, I'm making a proposal in this PR to move this information slightly higher in the doc and give it a dedicated section.

For more context, see my question on Discord.

I hope you'll consider making this small change. Thank you!

Copy link

codesandbox bot commented Jul 21, 2024

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

Copy link

codesandbox-ci bot commented Jul 21, 2024

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 873a647:

Sandbox Source
@examples-query-react/basic Configuration
@examples-query-react/advanced Configuration
@examples-action-listener/counter Configuration
rtk-esm-cra Configuration

Copy link

netlify bot commented Jul 21, 2024

Deploy Preview for redux-starter-kit-docs ready!

Name Link
🔨 Latest commit 873a647
🔍 Latest deploy log https://app.netlify.com/sites/redux-starter-kit-docs/deploys/66a477c27d71450008bd4921
😎 Deploy Preview https://deploy-preview-4523--redux-starter-kit-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@markerikson
Copy link
Collaborator

Not sure about the "in the component" part. The preferred approach would be to use await dispatch(myAsyncThunk()).unwrap(), which would actually throw an error:

@EvHaus
Copy link
Author

EvHaus commented Jul 22, 2024

The content, including "in the component" is a copy/paste of the existing doc. Just moved.

@EvHaus
Copy link
Author

EvHaus commented Jul 27, 2024

Pushed a new update that instead promotes the use of .unwrap() rather than modifying the previous docs.

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.

2 participants