I need to verify the existence of a property on an object, where the property exists only in CellDetails
and not in ContentCellUpdate
.
At present, I am using the following code:
if(cell.button)
The 'cell' object can be either CellDetails or ContentCellUpdate.
But I encounter a TypeScript error that says,
Property 'button' does not exist on type 'CellDetails | ContentCellUpdate'. Property 'button' does not exist on type 'ContentCellUpdate'
Here are the interfaces for each:
export interface CellDetails {
row: number;
col: any;
column: any;
content: ContentCell;
header: boolean;
button: ActionsButton | null;
reference: string;
history: boolean;
link: IPageContentLink | null;
image: boolean;
isColumnCheckbox: boolean;
permission: string;
inputStyles: string;
cell: HTMLDivElement;
}
and
export interface ContentCellUpdate {
row: number;
column: string;
content: ContentCellFormat;
}
I am considering adding,
button: ActionsButton | null;
to ContentCellUpdate, but I feel like this is treating the symptom rather than addressing the root cause. Is there a better approach to resolve this TypeScript error?