Skip to content

Please export the RequestInit interface #120

Description

@0x80

I originally wrote this helper function for a project using node-fetch and I want to port it to unfetch, but I'm missing the RequestInit interface.

Without it I don't know how to type the options.

importfetch,{RequestInit}from"isomorphic-unfetch";import{makeQueryString}from"../utils/query-string";exportasyncfunctionfetchJson<T>(endpoint: string,queryParams: {[key: string]: string|number|boolean}={},options: RequestInit={}): Promise<T>{constqueryString=makeQueryString(queryParams);consturl=`${endpoint}${queryString}`;constresponse=awaitfetch(url,{mode: "cors",
...options});if(!response.ok){thrownewError(`Fetch to ${url} failed with status ${response.status}. Response text: ${awaitresponse.text()}`);}try{returnresponse.json();}catch(err){thrownewError(`Failed to parse JSON from response of ${url}`);}}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions