In my TypeScript project, I have a type (which can also be implemented as an interface) that outlines all the possible handler names for queue message handling, along with the expected data types for each handler.
export type JobDataTypes = {
'user-handler': {
firstname: string;
};
'calendar-handler': {
memberId: number;
appointmentId: number;
};
};
Now, I am looking to create a function called
insertToQueue(jobType: keyof JobDataTypes, data) => void
that will only accept the correct data type based on the provided jobType
from the JobDataTypes
type above. Since I need this functionality in multiple places and don't want to hardcode it, how could I implement a type InsertToQueueParams
in order to achieve this goal?