Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does {| ... |} mean in javascript? [duplicate]

Reading through a javascript codebase, I encounter a block of code that looks like

export type RouteReducerProps = {|
  error?: Error,
  isResolving: boolean,
  isResolved: boolean,
  hasFailed: boolean,
|};

This looks like a javascript object literal definition, but I've never seen a javascript object literal with vertical bars inside the curly braces. What do those do?

like image 345
Andrew Farrell Avatar asked Feb 07 '18 13:02

Andrew Farrell


1 Answers

This syntax is specific to Flow, a static type checker for javascript. It defines an Exact Object Type, which is an object for which a only a few specified keys are valid. In the example above, only the keys 'error?', 'isResolving', 'isResolved', and 'hasFailed' can be defined on the object RouteReducerProps.

like image 155
Andrew Farrell Avatar answered Oct 06 '22 13:10

Andrew Farrell