My challenge is to create a recursive style object that can handle style properties in a nested format. Despite trying various solutions from SO and Google, I'm still struggling to understand how to do this effectively.
interface Properties {
border?: string;
width?: string;
}
//# 1 Type attempt
type TRecursiveProperties = Properties & {
[index: string]: TRecursiveProperties;
};
//# 2 Interface attempt
interface IRecursiveProperties extends Properties {
[index: string]: IRecursiveProperties;
}
const test: TRecursiveProperties = {
border: '1px solid green',
isActive: {
border: '2px solid red',
'&:hover': {
border: '3px solid blue'
}
}
};
I hope that the Recursive properties will serve as a fallback or a way to exclude keys from the Properties object.
The two errors I encounter are:
Type alias 'TRecursiveProperties' circularly references itself.
Property 'width' of type 'string' is not assignable to string index type 'IRecursiveProperties'
Any suggestions on how I can resolve these issues?