最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to use isomorphic-fetch in typescript - Stack Overflow

programmeradmin11浏览0评论

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.

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.

Share Improve this question asked Jul 25, 2017 at 3:50 Krishna SatyaKrishna Satya 8752 gold badges10 silver badges21 bronze badges 1
  • 1 did you try to install it using npm ? npm install @types/isomorphic-fetch and import fetch like below: import * as fecth from 'isomorphic-fetch"; – DirtyMind Commented Dec 7, 2017 at 6:40
Add a ment  | 

1 Answer 1

Reset to default 5

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();
发布评论

评论列表(0)

  1. 暂无评论