简体   繁体   中英

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; I have the error:
Property 'COUNTRY' does not exist on type 'SourceType'<b r> SourceType extend the interface 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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