Skip to content
This repository has been archived by the owner on Nov 9, 2023. It is now read-only.

Change TypeScript import to match module definition #43

Merged
merged 4 commits into from
Oct 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as http from 'http';
import * as https from 'http';
import { Options as BaseRetryOptions } from 'async-retry';
import { Request, RequestInit, Response } from 'node-fetch';
import { Headers, Request, RequestInit, Response } from 'node-fetch';

export interface RetryOptions extends BaseRetryOptions {
maxRetryAfter?: number;
Expand All @@ -17,5 +17,14 @@ export type Fetch = (
options?: FetchOptions
) => Promise<Response>;

export default function SetupFetch(client?: Fetch, agentOptions?: http.AgentOptions | https.AgentOptions): Fetch;
export type FetchModule = {
default: Fetch;
Headers: typeof Headers;
}

export default function SetupFetch(
fetchModule?: FetchModule,
agentOptions?: http.AgentOptions | https.AgentOptions
): Fetch;

export * from 'node-fetch';
10 changes: 10 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,18 @@ if not provided, with the following settings:

## How to use

JavaScript

```js
const fetch = require('@zeit/fetch')(require('some-fetch-implementation'))
```

TypeScript

```typescript
import createFetch from "@zeit/fetch"
import * as fetch from "some-fetch-implementation";
const fetch = createFetch(fetch);
```

If no fetch implementation is supplied, it will attempt to use peerDep `node-fetch`.