Skip to content

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

@prabal-rje

Description

@prabal-rje

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions