相关疑难解决方法(0)

什么是Scala中更高级的kinded类型?

您可以在网上找到以下内容:

  1. 更高的kinded类型==类型构造函数?

    class AClass[T]{...} // For example, class List[T]
    
    Run Code Online (Sandbox Code Playgroud)

    有人说这是一种更高的kinded类型,因为它抽象了符合定义的类型.

    较高的kinded类型是采用其他类型并构造新类型的类型

    这些虽然也称为类型构造函数.(例如,在Scala编程).

  2. 更高的kinded type == type构造函数,它将类型构造函数作为类型参数?

    更高级别的Generics中,您可以阅读

    ...抽象类型抽象的类型("更高级的类型")......"

    这表明

    class XClass[M[T]]{...} // or
    
    trait YTrait[N[_]]{...} // e.g. trait Functor[F[_]]
    
    Run Code Online (Sandbox Code Playgroud)

    是一种更高级的类型.

因此,考虑到这一点,很难区分类型构造函数,更高的kinded类型类型构造函数,它将类型构造函数作为类型参数,因此上面的问题.

generics constructor types scala higher-kinded-types

262
推荐指数
5
解决办法
6万
查看次数

TypeScript - 获取泛型类参数的类型

我需要实现一个GetClassParameter<T>像这样工作的类型:

class Foo<T> {

}

type foo = Foo<string>

type x = GetClassParameter<foo>; // should be string
Run Code Online (Sandbox Code Playgroud)

很抱歉,如果它是重复的,我找不到它。我只找到了一个硬编码的解决方案(来源):

type GetFooParameter<T extends Foo<any>> = T extends Foo<infer R> ? R : unknown;
Run Code Online (Sandbox Code Playgroud)

我试图做这样的事情:

class Foo<T> {
    public value: T;
    public value2: string;
    constructor (value: T) {
        this.value = value;
    }
}

type BaseT<T> = {
  value: T  // if removed, it wouldn't work
}
type GetClassParameter<T extends BaseT<any>> = T extends BaseT<infer R> ? R : unknown; …
Run Code Online (Sandbox Code Playgroud)

javascript typescript typescript-generics typescript-typings

6
推荐指数
1
解决办法
412
查看次数