Ts-toolbelt: Why is `<x> extends infer X ? <y> : never` so used?

Created on 26 Jun 2019  路  3Comments  路  Source: millsp/ts-toolbelt

馃 Question

Describe your question



The whole codebase is full of <x> extends infer X ? <y>: never

Search tags, topics



extends #infer #lots #used

question wiki

Most helpful comment

I use this syntax to defer the evaluation of a type... Otherwise TS evaluates all the types in their full depth. This causes performance issues and is irrelevant because we only want to compute when we've received the type parameters. As a result, the ts-toolbelt types load fast.

But it is not the only use case. Like I said above, TS can complain that a type is too deep to compute, then you can force it to compute step by step. So I especially use this on recursive types (which are much deeper because they're recursive).

All 3 comments

I use this syntax to defer the evaluation of a type... Otherwise TS evaluates all the types in their full depth. This causes performance issues and is irrelevant because we only want to compute when we've received the type parameters. As a result, the ts-toolbelt types load fast.

But it is not the only use case. Like I said above, TS can complain that a type is too deep to compute, then you can force it to compute step by step. So I especially use this on recursive types (which are much deeper because they're recursive).

Can you add an example of real code from this project that does this to this wiki entry? It's hard to understand if/how x and X are related in your pseudocode <x> extends infer X ? <y>: never (or if the x's are even relevant, which I think they aren't)

You can check this example out

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tonivj5 picture tonivj5  路  3Comments

ctrlplusb picture ctrlplusb  路  6Comments

thesunny picture thesunny  路  4Comments

mesqueeb picture mesqueeb  路  5Comments

ctrlplusb picture ctrlplusb  路  5Comments