是否可以创建一个代表函数签名的 object/class/interface?

Is it possible to create an object/class/interface that represents a signature of a function?

我的代码中的一切都已按预期运行。我想要的是让它变得冗长,使方法签名更容易解释(我知道我可以为此使用 Doc 注释,但我也想使用 TypeScript 类型) 并且可以通过 TSLint 更好地验证,例如。

今天我有这个:

class Test{
    testMetadada<T>(expression: (t: T) => void) {
        // ...
    }
}

expression对象是(t: T) => void类型的,不太好解释,我想这样:

class Expression<T> extends (t: T) => void{

}

interface Expression<T> extends (t: T) => void{

}

let Expression = ((t: T) => void)<T>;

所以我的方法是这样的:

class Test{
    testMetadada<T>(expression: Expression) {
        // ...
    }
}

其中Expression表示函数(t: T) => void.

有什么我可以用这种方式做的吗?

See here the example of what I'm trying to implement with this (the possibility of using Arrow function of TypeScript as expressions Lambda Expressions C# for metadata)

是,使用类型别名

type Expression<T> = (t: T) => void

https://www.typescriptlang.org/docs/handbook/advanced-types.html

在你的 class...

class Test {

    testMetadada<T>(expression: Expression<T>) {
        // ...
    }

}

Example updated with solution