A lightning presented at Beer.js Sofia about Flow. Flow is static type checker for JavaScript, made by Facebook.
FlowRadoslav Stankov 16/12/2016
View Slide
Radoslav Stankov@rstankovhttp://rstankov.comhttp://github.com/rstankov
https://github.com/facebook/flow
function double(a) {return a * 2;}
function double(a) {return a * 2;}var a = double("a");
/* @flow */function double(a) {return a * 2;}var a = double("a");
/* @flow */function double(a) {return a * 2;}var a = double("a");^ string.The operand of an arithmeticoperation must be a number.
/* @flow */function double(a) {return a * 2;}var a = double(1);
/* @flow */function double(a) {return a * 2;}var a = double(1);a.length;
/* @flow */function double(a) {return a * 2;}var a = double(1);a.length;^ property `length`Property not found in Number
export type User = {id: number,name: string,followersCount: number,postsCount: number,tagline: ?string,imageUuid?: string,};
function isFollowing(user: CurrentUser, topic: Topic): boolean {return user.followedTopicsIds.indexOf(topic.id) !== -1;}
function isFollowing(user: CurrentUser, topic: Topic): boolean {return user.followedTopicsIds.indexOf(topic.id) !== -1;}isFollowing(null, topic);isFollowing(user, null);isFollowing(user, somethingElse);
function isFollowing(user: CurrentUser, topic: Topic): boolean {return user.followedTopicsIds.indexOf(topic.id) !== -1;}isFollowing(null, topic);isFollowing(user, null);isFollowing(user, somethingElse);const variable: number = isFollowing(user, topic);
function isFollowing(user: CurrentUser, topic: Topic): boolean {return user.followedTopicsIds.indexOf(topic.id) !== -1;}isFollowing(null, topic);isFollowing(user, null);isFollowing(user, somethingElse);const variable: number = isFollowing(user, topic);const variable: boolean = isFollowing(user, topic);
function isFollowing(user: { followedTopicsIds: Array },topic: { id: number }): boolean {return user.followedTopicsIds.indexOf(topic.id) !== -1;}
class UserImage extends React.Component {props:{| user: User, width: number, height: number |} |{| user: User, variant: 'big' | 'medium' | 'small' |};render() { /* ... */ }}
const COUNTRIES = {BG: 'Bulgaria',US: 'United States',IT: 'Italy',FR: 'France',};type Country = $Keys;
const COUNTRIES = {BG: 'Bulgaria',US: 'United States',IT: 'Italy',FR: 'France',};type Country = $Keys;const missing: Country = 'missing';
const COUNTRIES = {BG: 'Bulgaria',US: 'United States',IT: 'Italy',FR: 'France',};type Country = $Keys;const missing: Country = 'missing';const italy: Country = 'IT';
Flow vs TypeScript static type checker structural type system no nullable by default no extra language features opt-in no runtime cost
https://speakerdeck.com/rstankov/beer-dot-js-flow
Thanks