Flow: incorrect "Missing type annotation for `U`." flow error triggered by adding `export`.

Created on 31 Aug 2018  路  5Comments  路  Source: facebook/flow

Here is a try flow

/* @flow */

type Thing = {
  prop: string
};

// no errors 
function myFunction(things: Array<Thing>) {
  return things.map(a => a);
}

// Missing type annotation for `U`. error
export function myFunction(things: Array<Thing>) {
  return things.map(a => a);
}

Most helpful comment

I think it's referring to the generic U in map's definition: https://github.com/facebook/flow/blob/master/lib/core.js#L247.

Changing the call to things.map<Thing>(a =>a) or specifying a return type of Array<Thing> for myFunction seems to fix it. It does seem weird that it only shows the error when the export is present though.

All 5 comments

I think it's referring to the generic U in map's definition: https://github.com/facebook/flow/blob/master/lib/core.js#L247.

Changing the call to things.map<Thing>(a =>a) or specifying a return type of Array<Thing> for myFunction seems to fix it. It does seem weird that it only shows the error when the export is present though.

got this too recently, not sure what that means

me too

Flow requires annotations on types in input positions reachable through exports. Until now, we were missing a lot of these cases. This is an example of a case we started catching recently. Even more recent changes, which will be shipped in v0.81.0, will hopefully make these errors clearer. I am also currently working on documentation for fixing these new errors when they appear.

just got this exception. for anyone else, explained here in more detail: https://medium.com/flow-type/asking-for-required-annotations-64d4f9c1edf8

Was this page helpful?
0 / 5 - 0 ratings