In my TypeScript project without React, I am dealing with an interface structured like this:
export interface LayerStyling<T> {
attribute: string;
value: AllowedTypes;
type: LayerTypes;
layout?: {
icon: string
};
state: {
[key in States]: ObjectType<T>
}
}
In this interface, the possible values for LayerTypes are "default" or "icon", and the presence of the "layout" key depends on the type selected.
If LayerTypes is set to "default", the interface will look like this:
export interface LayerStyling<T> {
attribute: string;
value: AllowedTypes;
type: LayerTypes;
state: {
[key in States]: ObjectType<T>
}
}
If LayerTypes is set to "icon", the interface will be slightly different:
export interface LayerStyling<T> {
attribute: string;
value: AllowedTypes;
type: LayerTypes;
layout: {
icon: string
};
state: {
[key in States]: ObjectType<T>
}
}
The presence of the "layout" key is determined by the "LayerTypes" value.
I encountered an issue while trying to access the "icon" property using:
const { layout: { icon } } = attrs; // It throws an error Property 'icon' does not exist on type '{ icon: string; } | undefined'.
I seek guidance on how to resolve this situation. Thank you!