类型“#e21c1a”不能分配给类型 'undefined'。在反应类型脚本中

Type '"#e21c1a"' is not assignable to type 'undefined'. in react type script

我正在为 viser 图表使用 React 类型脚本,颜色未定义 对此有任何解决方案

Type '"#e21c1a"' is not assignable to type 'undefined'.

代码部分

const eachView = function (view:any, facet:any) {
        var data = facet.data;
        var color = void 0;
        if (data[0].type === 'PolicyIssued') {

            color = '#e21c1a';
        }
        data.push({
            type: 'Customer',
            value: 100 - data[0].value
        });
        view.source(data);
        view.coord('theta', {
            radius: 0.8,
            innerRadius: 0.5
        });
        view.intervalStack().position('value').color('type', [color, '#eceef1']).opacity(1);
        view.guide().html({
            position: ['50%', '50%'],
            html: '<div class="g2s-guide-html" ><p class="title" style=" font-size: 12px;\n' +
                '    color: #8c8c8c;\n' +
                '    text-align: center;\n' +
                '    font-weight: 300;" >' + data[0].type + '</p><p class="value" style=" font-size: 18px;\n' +
                '    text-align: center;\n' +
                '    color: #000;\n' +
                '    font-weight: bold;">' + (data[0].value + '%') + '</p></div>'
        });
    }

我找到了解决方案 我将 var color = void 0; 替换为 var color = '#e21c1a';