In my current .d.ts
file, I have defined the following types:
type TransactionRowTypes = {
// transaction row types
}
type UserDataTypes = {
// user data types
}
type InventoryRowTypes = {
// inventory row types
}
type EventClientEvent = {
event: 'transactions' | 'userchange' | 'inventory';
time: number;
payload: Array<any>;
};
I am aiming to assign specific types to the payload
property based on the value of EventClientEvent.event
. For instance, if EventClientEvent.event
is set to transactions
, then I want the payload
type to be TransactionRowTypes
. Similarly, if it's userchange
, then the type should be UserDataTypes
, and so forth. I'm grappling with implementing conditional typing within an object type and unsure if I'm approaching this correctly. Though I do have a type extractor, I'm uncertain how to utilize it.
type EventName<T extends {event: string}> = T["event"];
If anyone can offer guidance or direct me towards resources that could assist me in resolving this dilemma, I would greatly appreciate it. Thank you.