I have a code where I have these interfaces and type defined:
export interface ReportItem {
title: string;
earnings: number;
}
export interface CustomError {
errorRaw: any;
}
export type SalesReport = ReportItem[];
Then I have a method that accepts a parameter, which may be of type SalesReport, but might also be a CustomError:
public getReport(data: SalesReport | CustomError) {
if ('errorRaw' in data) {
data.errorRaw // error
}
}
The reference to errorRaw field in data throws an error. What change do I need to make so it would work properly?
Thanks.