Flow: Missing type annotation for T
Asked Answered
G

2

11

We have a pure component, and we are trying to convert this to the Flow type safety. The application is using this component as a HOC ( High-Order Component). It is generating a context and injecting to the dispatched components.

Therefore, one method of the HOC is returning an object literal which is involving many binding operations. In this key-value pairs, there is one expression we didn't handle.

We are getting an error about missing notation:

Missing type annotation for T. T is a type parameter declared in array type [1] and was implicitly instantiated at call of method filter [2].

export type PropsType = {
  reviewConf ? : Object,
 ...
}

export type ContextType = {
  registerComponent: () => void,
  errors ? : Array < any >
  ...
}

export type StateType = {
  meta: Object
}

class AbstractPureFormComponent extends React.PureComponent < PropsType, StateType > {
    constructor(props: PropsType, context: ContextType) {
      super(props, context)

      this.state = {
        meta: {}
      }

    }
    getChildContext() {
        return {
          registerComponent: this.registerComponent.bind(this),
          ...



          errors: Object.keys(this.state.meta).filter(
                  name => this.state && this.state.meta[name].error
          )
       }
     }
   }
}

So what is the best practice for typing this error: key? Should it be an interface or type or something else...

Greengrocery answered 15/11, 2018 at 9:59 Comment(0)
P
14

I just encountered this issue with a function that simply clones and sorts an array, e.g.

const sortArray = (myArr: MyArray[]) => [...myArr].sort((a, b) => a > b ? -1 : 1)

What solved it for me was simply typing the return value of sortArray:

const sortArray = (myArr: MyArray[]): MyArray[] => [...myArr].sort((a, b) => a > b ? -1 : 1)
Provenance answered 11/1, 2019 at 19:20 Comment(0)
V
-1

The adjust is simpler than it, the problem is your variable is "array: Array<MyArray>", and "sort" return "array: MyArray[]", so, just change your variable to "array: MyArray[]".

Valoniah answered 29/6, 2021 at 14:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.