infer
- 表示待推断类型
type ParamType<T> = T extends (...args: infer P) => any ? P : T;
- 如果
T
能赋值给(...args: infer P) => any
, 结果是(...args: infer P) => any
否则返回T
interface User {
name: string;
age: number;
}
type Func = (user: User) => void;
type Param = ParamType<Func>; // Param = User
type AA = ParamType<string>; // string
网友评论