Aflred
Aflred

Reputation: 4593

FlowTyped function type inside object

I am trying to include function signature inside a type.

type validatorAction = {
  validatorFN: function method(str, bool, ...nums) {

  },
  errorKey: string,
  errorMessage: string
}

Tried multiple variations but none of them work and the documentation are horrible.

Upvotes: 0

Views: 31

Answers (1)

Aleksey L.
Aleksey L.

Reputation: 37918

You shouldn't include function implementation in type declaration but specify its (function's) type:

type validatorAction = {
  validatorFN: (string, boolean, ...number[]) => boolean,
  errorKey: string,
  errorMessage: string
}

And here's version with parameter names:

validatorFN: (str: string, bool: boolean, ...nums: number[]) => void

Documentation

Upvotes: 2

Related Questions