简体   繁体   English

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

[英]Error reassigning a value to an object property

I can get the value, but not reassign another one;我可以获得该值,但不能重新分配另一个值; why?为什么?

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;
        };
    }
}

In record.COUNTRY = newCountry;在记录中。COUNTRY = newCountry; I have the error:我有错误:
Property 'COUNTRY' does not exist on type 'SourceType'<b r> SourceType extend the interface StdMap<T = string> {[key: string]: T;}属性 'COUNTRY' 不存在于类型 'SourceType' <br> SourceType 扩展接口 StdMap<T = string> {[key: string]: T;}

I solved by changing the type of the input parameter: from我通过改变输入参数的类型来解决:从

record: SourceType

to

record: {COUNTRY: string}

It is still unclear why the compiler throws the value assignment error.目前还不清楚为什么编译器会抛出赋值错误。

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

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