繁体   English   中英

将值重新分配给对象属性时出错

[英]Error reassigning a value to an object property

我可以获得该值,但不能重新分配另一个值; 为什么?

export default class RemCpPluginHandler<
    SourceType extends StdMap<string | number>
> extends StdFileBasedPluginHandler<StdMap<string | number>> {
    constructor(configuration: CollectorConfiguration) {
        super(configuration);

        this.dataProcessor.recordPreProcessor.preprocessRecord = (
            record: SourceType
        ) => {
            const newCountry = record.COUNTRY.toString().replace(
                /[0-9]*\. /gi,
                ""
            );
            record.COUNTRY = newCountry;
            return record;
        };
    }
}

在记录中。COUNTRY = newCountry; 我有错误:
属性 'COUNTRY' 不存在于类型 'SourceType' <br> SourceType 扩展接口 StdMap<T = string> {[key: string]: T;}

我通过改变输入参数的类型来解决:从

record: SourceType

record: {COUNTRY: string}

目前还不清楚为什么编译器会抛出赋值错误。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM