Skip to content

Latest commit

 

History

History
92 lines (77 loc) · 3.52 KB

flow-type.md

File metadata and controls

92 lines (77 loc) · 3.52 KB
._   _       _            
| \ | | ___ | |_ ___  ___
|  \| |/ _ \| __/ _ \/ __|
| |\  | (_) | ||  __/\__ \
|_| \_|\___/ \__\___||___/

Flow

Tools

Still some rough patches

  • $Keys types values missing in autocomplete
    • Example of editor tooling not being caught up with the actual type checking
  • No @decorator support
    • Really a bummer when using MobX
  • No platform-specific support (RN's index.android.js) - issue
  • Sometimes confusing error messages

Companies using Flow

Style

Array<Foo>, not Foo[]

Why?

FAQ

Children

import React from 'react';
import type { Children } from 'react';
type Props = {
  children?: Children,
};
const SampleText = (props: Props) => (
  <div>{props.children}</div>
);

from https://stackoverflow.com/questions/40651126/flow-type-annotation-for-children-react-elements

binding methods in class gives me some "Covariant" errors

Must type them as Function in class:

class HeaderContainer extends React.Component {

  handleNavigate: Function;
  toggleMenu: Function;

  constructor(props: Object) {
    super(props);
    this.handleNavigate = this.handleNavigate.bind(this);
    this.toggleMenu = this.toggleMenu.bind(this);
  }

  handleNavigate() {
    console.log('hey');
  }

  toggleMenu() {
    console.log('ho');
  }

  render() {
    return (
      <div />
    );
  }
}

from ryyppy/flow-guide#6

DefaultProps get nullable type errors

"You don’t have to mark your defaultProps as optional properties in your props. Flow knows how to handle them properly." from official docs

How to type-check HOCs?

Typing Higher-order Components in Recompose With Flow