Skip to content

Flow is a static type checker for your JavaScript code. It does a lot of work to make you more productive. Making you code faster, smarter, more confidently, and to a bigger scale.

Notifications You must be signed in to change notification settings

cheatsheetmaker/FlowJS-Cheat-Sheet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 

Repository files navigation

FlowJS-Cheat-Sheet

Flow is a static type checker for your JavaScript code. It does a lot of work to make you more productive. Making you code faster, smarter, more confidently, and to a bigger scale.

https://cheatsheetmaker.com/flow

References

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

function fetch (callback: Callback) {
  ···
}

[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()

[Advanced features] React

type Props = {
  bar: number,
}

type State = {
  open: boolean,
}

class Foo extends React.Component<Props, State> {
  // Component code
}

[Advanced features] Comment syntax

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

function add(n /*: number */) { ... }

[Advanced features] Imports

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

[Advanced features] Functions

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

See: Functions

[Advanced features] Interfaces

interface Jsonable {
  toJSON(): string
}

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

(new Foo: Jsonable)

See: Interfaces

[Advanced features] Generic classes

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

var n: GenericClass<number> = new GenericClass(0)

See: Generic classes

[Advanced features] Type aliases

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

type Generic<T> = {
  foo: T
}

See: Type aliases

About

Flow is a static type checker for your JavaScript code. It does a lot of work to make you more productive. Making you code faster, smarter, more confidently, and to a bigger scale.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published