How do you hint different options for a function's object parameter?

0

Issue

I’m implementing a library in TypeScript and some functions are as follows:

constructor(type: TypeEnum, params: {[id:string]: any})

The thing is, whenever I use the library using js, I would like my IDE to display every single valid id of params. I have seen some libraries already do this, how do I achieve it?

Solution

You can just set them explicitly as properties:

constructor(type: TypeEnum, params: { option1?: any, option2?: any })

Answered By – skara9

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave A Reply

Your email address will not be published.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More