• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: How pass a interface’s property as parameter in typescript?

Resolved: How pass a interface’s property as parameter in typescript?

0
By Isaac Tonny on 17/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

Sorry if this question is too stupid ๐Ÿ˜€
I have an interface:
And a const, like routes config.
I want to declare a function, it will take one of those route as parameter:
The problem is, I don’t know how to make this function only accept one of the APIRoutes properties.
I mean something like this:
How can I do this? Not only interface, whatever can solve this problem is great.
Thanks

Answer:

You need keyof operator. It takes an object type and produces a union of its keys.
Link

If you have better answer, please add a comment about this, thank you!

typescript
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: Is pandas groupby() function always produce a DataFrame with the same order respect to the column we group by?

24/03/2023

Resolved: Kivy widget hierarchy not behaving as expected

24/03/2023

Resolved: Pandas Groupby Get Values from Previous Group

24/03/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.