timothyclifford timothyclifford - 1 year ago 175
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>;


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 Source

This syntax?

import fetch, { Response } from 'node-fetch';
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download