Flow: Using Iterable as a function argument causes gen-flow-files to crash

Created on 27 Jan 2017  路  8Comments  路  Source: facebook/flow

Running gen-flow-files on any of these snippets causes it to crash with:
Error: Failure("/path/to/IterableRepro.js: Failure(\"Unexpected global type: PolyT\")")

Flow version: 0.38.0
No libdefs, blank .flowconfig

// @flow
export default class IterableReproClass {
  constructor(arg: Iterable<number>) {}
}
// @flow
export default function IterableReproFunction(arg: Iterable<number>) {}



md5-42a5933f6ed5b4ca2ca8cf40d7995533



```js
export type IterableReproReturnType = {
  someFunction(): Iterable<number>;
}



md5-6a64c2e522a077ff57d7671ad449be73



```js
export const iterableReproConst: Iterable<number> = [1, 2, 3];

Most helpful comment

In case it's helpful, I ran into this and was able to reduce my code to this for reproducing the issue:

// @flow
import type { Node } from 'react'

function myFn(node: Node) {
  return node
}

export default myFn

The error I get looks like this:

$ ./node_modules/.bin/flow gen-flow-files src/index.js 
Error: Failure("<path-to-file>/src/index.js: Failure(\"Unexpected global type: PolyT\")")

in case you're interested, here's the actual file

// @flow
import React from 'react'
import type { Node } from 'react'

type Props = {
  initialState: {},
  render: ({ state: {}, setState: Function }) => Node,
}

type State = {}

class Comp extends React.Component<Props, State> {
  static defaultProps = {
    initialState: {},
    render: () => null,
  }
  state = this.props.initialState
  setState = this.setState.bind(this)
  render() {
    const { state, setState } = this
    return this.props.render({ state, setState })
  }
}

export default Comp

I'm unsure how to resolve this, but it appears to be related to the original issue...

All 8 comments

Hello darkness my old friend...

I'm having the same kind of error; i.e. Failure(\"Unexpected global type: AnyT\")")

My instinct tells me it's due to me using a SyntheticEvent<> type that it's globally accessible when using Flow, but the gen-flow-files expects this type to be explicitly imported.

Let's see if I still have this error after I explicitly import these types...

Ok, I changed those types for any and I still got the same error. Seems I can't use gen-flow-files for generating type definitions for my library, since I have no idea what the error is related to :(

In case it's helpful, I ran into this and was able to reduce my code to this for reproducing the issue:

// @flow
import type { Node } from 'react'

function myFn(node: Node) {
  return node
}

export default myFn

The error I get looks like this:

$ ./node_modules/.bin/flow gen-flow-files src/index.js 
Error: Failure("<path-to-file>/src/index.js: Failure(\"Unexpected global type: PolyT\")")

in case you're interested, here's the actual file

// @flow
import React from 'react'
import type { Node } from 'react'

type Props = {
  initialState: {},
  render: ({ state: {}, setState: Function }) => Node,
}

type State = {}

class Comp extends React.Component<Props, State> {
  static defaultProps = {
    initialState: {},
    render: () => null,
  }
  state = this.props.initialState
  setState = this.setState.bind(this)
  render() {
    const { state, setState } = this
    return this.props.render({ state, setState })
  }
}

export default Comp

I'm unsure how to resolve this, but it appears to be related to the original issue...

Also, in case it's helpful to anyone looking for a workaround, I posted about this to my newsletter today.

I got this error in another case:

Error: Failure("<path>src\\index.js: Failure(\"Unexpected global type: AnyT\")")

flow gen-flow-files ./src/index.js --out-dir ./dist
index.js

// @flow
import { Message } from './Message';
import { DispatcherContext } from './DispatcherContext';
...
export {
  Message,
  DispatcherContext,
...
};

I manage to find workaround with:
flow gen-flow-files ./src/api.js --out-dir ./dist
api.js

// @flow
export * from './index';

I'm seeing the same issue as @idanilt and @kentcdodds but their workaround doesn't seem to do the trick for me still seeing the following error:

Error: Failure("<path-to-file>/src/index.js: Failure(\"Unexpected global type: PolyT\")")

This seems to be oddly infectious? I had a React functional component which worked fine with gen-flow-types, then added Node as a return type, and got this error. Removed the return type again, restoring the code that had previously worked - but the PolyT error has not gone away.

A cache problem, or similar?

same issue here. I have defined some flow types in a types.js file and get this error when running flow gen-flow-files src/types.js:

Failure(\"Unexpected global type: PolyT\")")

gen-flow-files is removed. A replacement is coming soon.

Was this page helpful?
0 / 5 - 0 ratings