Here is the interface I am working with:
export interface IRenderStruct {
type: string;
props: {
className?: string;
children?: (string | IRenderStruct) | (string | IRenderStruct)[];
[propName: string]: any;
};
}
The objects created based on this interface can have nested structures through elm.props.children
. While writing unit tests, I encountered a scenario where I am certain that a RenderStruct object will be the child of another object. There will not be a string or an array of RenderStruct objects as children.
However, when attempting to access the type
property like so:
expect(result.props.children.type === 'something');
The TypeScript compiler raises an error stating that I cannot access the type
property because children
may be a string which does not have the type
property.
I am aware of the structure in this particular case. How can I explicitly inform TypeScript about this?