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

useJsonBody() hook incorrectly claims to return string | undefined values in TypeScript #759

Open
prabal-rje opened this issue May 1, 2024 · 0 comments

Comments

@prabal-rje
Copy link

prabal-rje commented May 1, 2024

The useJsonBody() hook for the API client in SST claims to return string | undefined values only, but if the JSON body contains a list of strings, you need to do weird 'type magic' to make it work.

Here's a sample code snippet in TS:

const {
  some_str,
  some_str_list
} = useJsonBody();

Here's TS claiming they must all be string | undefined:
image

Here's how I got around the problem:

const str_list = some_str_list as unknown as string[]

EDIT: I am a JS/TS n00b so I apologize if the bug report is nonsense.

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

No branches or pull requests

1 participant