typescript - 如何在泛型类型中要求泛型类型参数?
问题描述
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
?
谢谢。
解决方案
推荐阅读
- reactjs - 为什么我的 React Redux TypeScript 应用程序除了 iPhone 6 iOS 12.0.1(它是一个空白屏幕)之外的任何地方都可以工作?
- android - 如何通过传入参数从 AsyncTask 中检索对象列表?
- android - 我应该使用什么 SHA-1 证书指纹来发布构建 apk?
- user-interface - 我的无状态小部件触发了我无法分配的错误消息
- javascript - 我应该一次加载数据库结果还是发出多个请求?
- r - Cbind 未按预期工作时间序列对象 R
- c++ - Opencv 编译无法使用 -lopencv_videoio
- arrays - 如何找到一组特定值在数组中出现的次数?
- html - 如何删除重复的 HTML 元素?
- flutter - 如何在flutter中使用动态全局列表