Skip to content

Instantly share code, notes, and snippets.

@gmmorris
Created December 14, 2016 11:34
Show Gist options
  • Save gmmorris/332e089412311da9aca77550d413e072 to your computer and use it in GitHub Desktop.
Save gmmorris/332e089412311da9aca77550d413e072 to your computer and use it in GitHub Desktop.
Flow is failing to infer instanceof checks
/* @flow */
function Children (children : Iterable<any>) {
this.children = Array.from(children)
return this
}
Children.prototype = {
toArray () : any[] {
return this.children
},
get length () : number {
return this.children.length
},
[Symbol.iterator] () : Iterator<any> {
return this.children[Symbol.iterator]()
}
}
const asChildren = (children : Iterable<any> = []) : Children =>
isChildren(Children)
? children
: new Children(children)
const isChildren =
(children : ?any) : boolean =>
children instanceof Children
/* @flow */
function Children (children : Iterable<any>) {
this.children = Array.from(children)
return this
}
Children.prototype = {
toArray () : any[] {
return this.children
},
get length () : number {
return this.children.length
},
[Symbol.iterator] () : Iterator<any> {
return this.children[Symbol.iterator]()
}
}
const asChildren = (children : Iterable<any> = []) : Children =>
children instanceof Children
? children
: new Children(children)
const isChildren =
(children : ?any) : boolean =>
children instanceof Children
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment