Daily-Question icon indicating copy to clipboard operation
Daily-Question copied to clipboard

【Q707】请简述 typescript 中的 infer

Open shfshanyue opened this issue 3 years ago • 2 comments

shfshanyue avatar Oct 03 '21 13:10 shfshanyue

和returnType有点关联,做返回值推断的

okbug avatar Nov 14 '21 02:11 okbug

infer 表示在 extends 条件语句中待推断的类型变量。

例子:

/**
 * Obtain the parameters of a function type in a tuple
 */
type Parameters<T extends (...args: any) => any> = T extends (...args: infer P) => any ? P : never;

image

canvascat avatar May 19 '22 03:05 canvascat