Javascript 如何注释作为对象属性的函数?

Javascript 如何注释作为对象属性的函数?,javascript,flowtype,Javascript,Flowtype,我有以下类型别名: type TestType = { critical: string, failProps: Object, successProps: ?Object, test: Function, }; 我想说得更具体一些。该功能应具有以下特征: function (value: string): boolean { /* ... */ } 如何指示测试应采用单个字符串参数并返回布尔值?您可以使用以下语法: type TestType = { critical:

我有以下类型别名:

type TestType = {
  critical: string,
  failProps: Object,
  successProps: ?Object,
  test: Function,
};
我想说得更具体一些。该功能应具有以下特征:

function (value: string): boolean { /* ... */ }

如何指示测试应采用单个字符串参数并返回布尔值?

您可以使用以下语法:

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,
};

您可以使用以下语法:

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,
};