首页 > 解决方案 > 如何在泛型类型中要求泛型类型参数?

问题描述

type RetuType<T> = () => T
type RetuGeneric<T, G> = () => G<T>

const f: RetuType<number> = () => 114514 // OK
const g: RetuGeneric<number, RetuType> = () => 114514 // Error: Type `G` is not genric.

另一个例子事实上我正在研究一种混合类型。

type Ctor<T = object> = new (...arg: any[]) => T
type Mixin<I, S> = <T> (B: Ctor<T>) => Ctor<I> & S<I>
// I and S stand for instance type and static type.

如何写一个合适的RetuGeneric
谢谢。

标签: typescripttypescript-generics

解决方案


推荐阅读