DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’» is a community of 963,503 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
LΓ’m
LΓ’m

Posted on

FlowJS Cheat Sheet

A JavaScript library providing multiple simultaneous, stable, fault-tolerant, and resumable/restartable file uploads via the HTML5 File API.

References

type Callback = (?Error, string) => any

function fetch (callback: Callback) {
  Β·Β·Β·
}
Enter fullscreen mode Exit fullscreen mode

[Examples] Examples

var myNumbers: Array<number> = [42]
function foo(): any { return 42 }
var b: boolean = false
var b: ?boolean = false  /* maybe */
var b: string | boolean = false

var a: Class<MyClass> = MyClass
var b: MyClass = new a()
Enter fullscreen mode Exit fullscreen mode

[Advanced features] React

type Props = {
  bar: number,
}

type State = {
  open: boolean,
}

class Foo extends React.Component<Props, State> {
  // Component code
}
Enter fullscreen mode Exit fullscreen mode

[Advanced features] Comment syntax

/*::
  export type Foo = { ... }
*/

function add(n /*: number */) { ... }
Enter fullscreen mode Exit fullscreen mode

[Advanced features] Imports

import type { Person } from '../person'
import typeof Config from '../config'
Enter fullscreen mode Exit fullscreen mode
export type Person = { id: string }
Enter fullscreen mode Exit fullscreen mode

[Advanced features] Functions

const callback: () => void = function () {}
Enter fullscreen mode Exit fullscreen mode
function filter<T> (
  list: Array<T>,
  callback: (item: T) => boolean
): Array<T> {
  Β·Β·Β·
}
Enter fullscreen mode Exit fullscreen mode

See: Functions

[Advanced features] Interfaces

interface Jsonable {
  toJSON(): string
}

class Foo {
  toJSON() { return '{}' }
}

(new Foo: Jsonable)
Enter fullscreen mode Exit fullscreen mode

See: Interfaces

[Advanced features] Generic classes

class GenericClass<T> {
  x: T
  constructor (x: T) { ... }
}

var n: GenericClass<number> = new GenericClass(0)
Enter fullscreen mode Exit fullscreen mode

See: Generic classes

[Advanced features] Type aliases

type Tree = {
  foo: string,
  bar: number,
  qux: (foo: string, bar: number) => boolean
}

type Generic<T> = {
  foo: T
}
Enter fullscreen mode Exit fullscreen mode

See: Type aliases

Top comments (0)

In defense of the modern web

I expect I'll annoy everyone with this post: the anti-JavaScript crusaders, justly aghast at how much of the stuff we slather onto modern websites; the people arguing the web is a broken platform for interactive applications anyway and we should start over;

React users; the old guard with their artisanal JS and hand authored HTML; and Tom MacWright, someone I've admired from afar since I first became aware of his work on Mapbox many years ago. But I guess that's the price of having opinions.