Skip to content

Incorrect return type for CompletedBody.getJson #155

Open
@leumasme

Description

@leumasme

Implementation

async getJson() {
return runAsyncOrUndefined(async () =>
JSON.parse((await completedBody.getText())!)
)
},

Types (why are these even separate?)

mockttp/src/types.ts

Lines 176 to 181 in b50532a

/**
* The contents of the response, decoded, parsed as UTF-8 string, and
* then parsed a JSON. The response is decoded and returned asynchronously
* as a Promise.
*/
getJson(): Promise<object | undefined>;

JSON.parse can not return undefined (but can return null, which is not the same) and can return more than just objects (numbers, strings).
Probably best to just type getJson as Promise just like JSON.parse is typed as any.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions