timothyclifford timothyclifford - 16 days ago 7
TypeScript Question

TypeScript import syntax

I'm using node-fetch with TypeScript.

I want to access the fetch function and also the Resource interface which are defined in the type definition as:

export default function fetch(url: string | Request, init?: RequestInit): Promise<Response>;


and

export class Response extends Body {
// ...
}


In my TypeScript file I'm importing these separately using:

import fetch from 'node-fetch';
import { Response } from 'node-fetch';


Is there a nicer, single line way to do this?

Answer

This syntax?

import fetch, { Response } from 'node-fetch';