links: TypeScript MOC


Represent an object type with dynamic keys

Let’s assume there is a object which takes date string as key and array of events as value

const upcomingEvents = {
	"19-01-2021": [
		{
			title: "Read You Don't Know JS"; 
			kind: "Event"; 
			startDate: "19-01-2021"; 
			endDate: "19-01-2021";
		},
		{
			title: "Drink water"; 
			kind: "Reminder"; 
			startDate: "19-01-2021"; 
			endDate: "19-01-2021";
		}
	],
	"20-01-2021": [...],
}

Here the keys are strings and values are array of objects

export interface IEvent { 
	title: string; 
	kind: string; 
	startDate: string;
	endDate: string; 
} 
export interface IEvents { 
	[key: string]: IEvent[] 
}
 
const upcomingEvents: IEvents = {
	// ... events
}

tags: typescript