Currently in the process of upgrading my Angular project to version 13 within a new workspace. While transferring code, I encountered a typescript-eslint error that has me stumped.
The previous working code looked like this:
interface IConfigurationSetting {
category?: string,
key?: string,
value?: string | number,
message?: string
}
export class ConfigurationSetting implements IConfigurationSetting {
category: string;
key: string;
value: string | number;
message: string;
constructor(options: IConfigurationSetting = {}) {
this.category = options.category || '';
this.key = options.key || '';
this.value = options.value || '';
this.message = options.message || '';
}
}
export class ConfigurationSettingsGroup {
settings: ConfigurationSetting[];
errors: string[];
constructor(options: {
settings?: ConfigurationSetting[],
errors?: string[]
} = {}) {
this.settings = (options.settings || []).map(setting => new ConfigurationSetting(setting));
this.errors = options.errors || [];
}
}
After running the VSC eslint check with the new setup, an error is now triggered for the setting parameter in the new ConfigurationSetting(setting) call - "Unsafe argument of type 'any' assigned to a parameter of type 'IConfigurationSetting'".
I structured my classes in this way to ensure that properties of complex objects or arrays have necessary defaults. Is it still acceptable to map arrays of complex objects as shown above? If yes, how can I resolve this unsafe rule violation without completely disabling it? Alternatively, is there a more effective method for mapping arrays of complex object types?
UPDATE: I made a modification that eliminated the "Unsafe argument of type 'any' assigned to a parameter of type 'IConfigurationSetting'" error:
this.settings = <ConfigurationSetting[]>(options.settings || []).map((setting: ConfigurationSetting) => new ConfigurationSetting(setting));
Despite this change, I am still encountering a typescript-eslint error:
Unsafe call of an `any' typed value. eslint(@typescript-eslint/no-unsafe-call)
This error specifically occurs at (options.settings || []).map. Any suggestions on resolving this issue would be greatly appreciated.