Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using Iterable as a function argument causes gen-flow-files to crash #3281

Closed
billschaller opened this issue Jan 27, 2017 · 8 comments
Closed

Comments

@billschaller
Copy link
Contributor

billschaller commented Jan 27, 2017

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>) {}
export type IterableReproArgType = {
  someFunction(arg: Iterable<number>): void;
}
export type IterableReproReturnType = {
  someFunction(): Iterable<number>;
}
export type IterableReproPropType = {
  thing: Iterable<number>;
}
export const iterableReproConst: Iterable<number> = [1, 2, 3];
@DrummerHead
Copy link

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 :(

@kentcdodds
Copy link

kentcdodds commented Nov 13, 2017

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...

@kentcdodds
Copy link

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

@idanilt
Copy link

idanilt commented Dec 10, 2017

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';

@arahansen
Copy link

arahansen commented Dec 15, 2017

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\")")

@gertsonderby
Copy link

gertsonderby commented Mar 22, 2018

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?

@macrozone
Copy link

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\")")

@TrySound
Copy link
Contributor

TrySound commented Feb 9, 2019

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

@TrySound TrySound closed this as completed Feb 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants