Krishna Satya
Krishna Satya

Reputation: 875

How to use isomorphic-fetch in typescript

I am getting error @types/isomorphic-fetch has no default export fetch

import fetch from 'isomorphic-fetch';

export const AUTH_FAIL = "AUTH_FAIL"
export const ERROR_FETCH = "EROR_FETCH";
export const SUCCESS_FETCH = "SUCESS_FETCH";
export const START_FETCH = "START_FETCH";

export function start_fetch(){ 
    return function(dispatch: any){
        return fetch("http://localhost:8000/api/data")
        .then(
            response => response.json()
        )
    }
}

thanks for your help.

Upvotes: 6

Views: 9359

Answers (1)

dallasg
dallasg

Reputation: 143

I was able to make it work by importing the library like this:

import 'isomorphic-fetch';

I had to polyfill ES6 Promises before that though. For example:

import * as e6p from "es6-promise";
(e6p as any).polyfill();

Upvotes: 5

Related Questions