I have a structure similar to this and I am trying to create definitions for types/interfaces, but I am facing issues in making it work correctly.
layoutsSet: {
1: {
"lg": [
{
i: "1",
x: 0,
y: 0,
w: 2,
h: 2
},
{
i: "2",
x: 2,
y: 0,
w: 2,
h: 2
},
{
i: "3",
x: 4,
y: 0,
w: 2,
h: 2
},
]
}
};
This is how it currently appears. However, I need to make some adjustments as I am encountering errors during compilation:
TS2322: Type '{ "lg": { i: string; x: number; y: number; w: number; h: number; }[]; }' is not assignable to type 'Layouts'. Property 'md' is missing in type '{ "lg": { i: string; x: number; y: number; w: number; h: number; }[]; }'.
export interface Layout {
i: string;
x: number;
y: number;
w: number;
h: number;
}
export enum Breakpoint {
LG = "lg",
MD = "md",
SM = "sm",
XS = "xs",
XXS = "xxs"
}
export interface LayoutBreakpoint extends Array<Layout> {}
export type Layouts = {
[b in Breakpoint]: LayoutBreakpoint
}
export interface LayoutsSet {
[index: number]: Layouts
}
What modifications should be made to ensure that it functions correctly? Any assistance would be greatly appreciated.
// EDIT
The interesting thing is that after changing
export type Layouts = {
[key: string]: LayoutBreakpoint
}
It started working...
However, why am I unable to define the index as an enum type?