Typescript error: Cannot redeclare block-scoped variable 'fetch'

Typescript error: Cannot redeclare block-scoped variable 'fetch'

我正在进行概念验证,以从 JSON-server 获取一些简单的 JSON 数据以显示在我的 React 应用程序中。在这样做时,我试图调用 fetch 来直接加载数据。当我这样做的时候。

ERROR: "cannot redeclare block-scoped variable 'fetch'.

我的问题是,在使用常规 Typescript 时,我该如何解决这个问题?

import React, { Component } from 'react';
import '../HeaderBar/HeaderBar.css';

type StatusBarProps = {};
type StatusBarState = {
    launch_timer: boolean;
    foreGroundTimer: number;

};
class StatusBar extends Component<StatusBarProps, StatusBarState> {
    timerId: number;
    constructor() {
        super();
        this.state = {
            launch_timer: true,
            foreGroundTimer: -1,
        };
    }
    componentDidMount() {
        window.fetch('localhost:3000/StatusComponent').then(results => {
            return results.json();
        }).then(data => {
            let systemOff = 'green';
            let systemOn = 'gray';
            let statusBarBlocks = data.StatusComponent.map((Status) => {
                return(
                    <div className="blockBar" id={Status.id} key={Status.key} style={{ backgroundColor: (this.state.foreGroundTimer >= Status.id) ? systemOff : systemOn }}> {Status.Name} </div>
                );
            });
            this.setState({statusBarBlocks: statusBarBlocks});
        });
    }
    componentWillUnmount() {
        clearInterval(this.timerId);
    }
    tick() {
        this.setState({ launch_timer: !this.state.launch_timer, foreGroundTimer: (this.state.foreGroundTimer + 1) % 26 });
    }
    render() {

        return (
            <div className="location">
                <div className="col-xs-6">
                {this.state.statusBarBlocks}
                </div>
            </div>
        );
    }
}
export default StatusBar;

编辑 1:问题的位置是@types/whatwg-fetch/index.d.ts 这让我相信这是打字稿的问题。我实施了 Isomorphic-fetch 但无济于事。

所以正在努力发现这个问题的原因。我发现在 Lib 文件和 @types/whatwg-fetch 中都声明了 fetch 的地方有重叠。卸载此依赖项允许程序编译。解决问题。

在此 SO post 找到。感谢芬顿的回答。