L
L
Leo_SAN2021-11-02 18:53:20
typescript
Leo_SAN, 2021-11-02 18:53:20

How can you call U differently when typing type InferValueTypes = T extends { [key: string]: infer U }? U: never?

type InferValueTypes = T extends { [key: string]: infer U } ? U : never
What is another name for U ?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Belyaev, 2021-11-02
@Leo_SAN

U is the name you enter, it can be any valid name instead:

type InferValueTypes<T> = T extends { [key: string]: infer IDontKnowWhat2CallThis } ? IDontKnowWhat2CallThis : never

In general, you should not use conditional types, especially with infer, where you can do without them:
type InferValueTypes<T extends Record<string, unknown>> = T[string];

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question