[Typescript] Variable assignment - extends infer X

You can use `extends infer X` to assign the result of an expression to a variable

type SomeFunction<U> = 
    SuperHeavyComputation<U> extends infer Result
    ? [Result, Result, Result]
    : never

 

The trick is to use `infer X` right after the `extends` keyword

posted @ 2022-11-17 15:11  Zhentiw  阅读(8)  评论(0编辑  收藏  举报