I have an object where its value is a method that takes in any number of parameters:
ts
export const ProductionRouteMetadata: {
[id: string]: (
...params: any
) => RouteMetadataItem<"Production">;
} = {
[RouteMetadataEnums.Production.GET_JOBS_BY_LOCATION]: (
location: string,
paginatedParams?: any
) => {
// Logic to create metadata
},
[RouteMetadataEnums.Production.GET_ALL_JOBS]: (paginatedParams?: any) => {
// Logic to create metadata
},
[RouteMetadataEnums.Production.GET_JOB]: (id: string) => ({
// Logic to create metadata
}),
[RouteMetadataEnums.Production.UPDATE_JOB]: (
id: string
): RouteMetadataItem<"Production"> => {
// Logic to create metadata
},
[RouteMetadataEnums.Production.ADD_JOB]: () => {
// Logic to create metadata
},
};
As you can see, each item in the object takes in a different params, or no params at all. Currently if I call any of these items, the generic type of (...params:any)
is shown in Intellisense. How can I have TypeScript reference the parameters of individual methods when I call it?
Subreddit
Post Details
- Posted
- 2 years ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/typescript/...