Coming soon - Get a detailed view of why an account is flagged as spam!
view details
14
How can I reference an individual function type when using a mapped object type?
Post Body

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?

Author
Account Strength
90%
Account Age
8 years
Verified Email
Yes
Verified Flair
No
Total Karma
1,041
Link Karma
556
Comment Karma
485
Profile updated: 5 days ago
Posts updated: 4 months ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
2 years ago