L
L
lavezzi12021-07-21 15:32:20
typescript
lavezzi1, 2021-07-21 15:32:20

How to get type of one from object key and use for function argument in TS?

Hello, there is a generic function that accepts a function that returns a promise with a given data type. The problem is that this data type can have a different unique key, id or uuid, while in the case of id it is a number, and uuid is a string. How to make TS understand that if the id key is available, then the argument accepted in the fetcher function must be a number, and if uuid, then a string?

https://www.typescriptlang.org/play?#code/C4TwDgpg...

Answer the question

In order to leave comments, you need to log in

2 answer(s)
W
WbICHA, 2021-07-21
@lavezzi1

https://www.typescriptlang.org/play?#code/C4TwDgpg...

A
Alex, 2021-07-21
@Kozack

https://www.typescriptlang.org/play?#code/C4TwDgpg...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question