更新 - 此问题的上下文是预先TypeScript 1.4.从那个版本开始,我的第一个猜测得到了语言的支持.请参阅答案的更新.
我可以声明f是一个接受字符串并返回字符串的函数:
var f : (string) => string
Run Code Online (Sandbox Code Playgroud)
我可以声明g是一个字符串数组:
var g : string[]
Run Code Online (Sandbox Code Playgroud)
如何声明h为"接受字符串并返回字符串的函数"的数组?
我的第一个猜测:
var h : ((string) => string)[]
Run Code Online (Sandbox Code Playgroud)
这似乎是一个语法错误.如果我拿掉额外的括号,那么它是一个从字符串到字符串数组的函数.
例子:
class Parent {
parentMethod() {
// ...
}
}
@Hooks({
// Only methods from the `Child` class (including inherited methods) must be allowed here
childMethod: [/* ... */],
parentMethod: [/* ... */]
})
class Child extends Parent {
childMethod() {
// ...
}
}
Run Code Online (Sandbox Code Playgroud)
所述@Hooks()装饰接受一个对象作为参数。在这个对象中,键是Child类中的方法名称。如何使@Hooks()装饰器类型安全?你能提供一个带有类型的代码示例@Hooks()吗?