我有以下类型别名:
type TestType = {
critical: string,
failProps: Object,
successProps: ?Object,
test: Function,
};
我想更加具体test
。该函数应具有此签名:
function (value: string): boolean { /* ... */ }
如何指示test
应采用单个字符串参数并返回布尔值?
答案 0 :(得分:5)
您可以使用以下语法:
type TestType = {
critical: string,
failProps: Object,
successProps: ?Object,
test: (value: string) => boolean,
};
...或者如果你想在其他地方重用函数类型:
type functionType = (value: string) => boolean
type TestType = {
critical: string,
failProps: Object,
successProps: ?Object,
test: functionType,
};