Skip to content

Instantly share code, notes, and snippets.

@taptapdan
Last active August 31, 2018 13:03
Show Gist options
  • Select an option

  • Save taptapdan/39ddd807335fe52eb50a8a0ab00d0350 to your computer and use it in GitHub Desktop.

Select an option

Save taptapdan/39ddd807335fe52eb50a8a0ab00d0350 to your computer and use it in GitHub Desktop.
Type Checking JavaScript

Type Checking JavaScript

TypeScript

Articles & Videos

Flow

Resources

Videos

  • Flow is great for your own code, but what about 3rd party libraries?
import express from 'express';
const app = express()
app.gettt() # doesn't exist, but flow doesn't know this
  • Flow type definition files!
yarn global add flow-typed
yarn add flow-bin --dev
# installs definition files for libraries found in node_modules
flow-typed install
  • Now, rerunning flow will return
property `gettt` Property not found in Application
  • Now imagine a script that reruns flow-typed install after every yarn add.
  • At 16:40, state machines:
// a "tagged union" to represent a state machine
type State = {
  screen: 'loading',
} | {
  screen: 'answering',
  problems: Array<Problem>,
  answers: Array<Answer>,
  currentProblem: number,
} | {
  screen: 'finished',
  pointsData: PointsData,
}
  • If you're making a ton of things optional, you're probably trying to represent a state machine poorly.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment