{"id":256,"date":"2016-03-25T18:00:00","date_gmt":"2016-03-25T09:00:00","guid":{"rendered":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/blog\/2016\/03\/25\/static-type-check-with-flow-type"},"modified":"2016-03-25T18:00:00","modified_gmt":"2016-03-25T09:00:00","slug":"static-type-check-with-flow-type","status":"publish","type":"post","link":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/blog\/2016\/03\/25\/static-type-check-with-flow-type\/","title":{"rendered":"Flowtype\u306b\u5165\u9580\u3057\u3066JavaScript\u30b3\u30fc\u30c9\u3067\u9759\u7684\u578b\u4ed8\u3051\u306e\u6069\u6075\u3092\u3046\u3051\u308b\u3068\u3053\u308d\u307e\u3067"},"content":{"rendered":"
\u30cf\u30a6\u30b9\u30fb\u30aa\u30d6\u30fb\u30ab\u30fc\u30c9<\/a>\u3067\u5bdd\u4e0d\u8db3\u306e\u5c0f\u98fc\u3067\u3059\u3002 <\/p>\n \u3055\u3066\u3001\u6700\u8fd1\u500b\u4eba\u7684\u306b \u5b9f\u884c\u6642\u306b\u691c\u51fa\u3055\u308c\u308b\u3064\u307e\u3089\u306a\u3044\u9593\u9055\u3044\u3084\u3001\u9593\u9055\u3063\u305f\u578b\u304c\u6e21\u3063\u3066\u304d\u305f\u6642\u306e\u9632\u5fa1\u30b3\u30fc\u30c9( \u73fe\u5728 \u4eca\u56de\u306f \u3053\u3093\u306a\u611f\u3058\u306e\u7c21\u5358\u306a\u3082\u306e\u3067\u3059 \u307e\u305a \u7279\u306b\u96e3\u3057\u3044\u3053\u3068\u306f\u3057\u3066\u3044\u306a\u3044\u3068\u601d\u3044\u307e\u3059\u3002 \u516c\u5f0f\u306e\u624b\u9806<\/a>\u3092\u53c2\u8003\u306b\u5c0e\u5165\u3057\u307e\u3059\u3002 Flow is a static type checker, designed to quickly find errors in JavaScript applications: \u5f93\u3063\u3066\u3001 \u30b7\u30f3\u30d7\u30eb\u306b \u203b ES Class Fields<\/a>\u3067 \u5404\u7a2e\u30b9\u30af\u30ea\u30d7\u30c8\u306f\u3053\u3093\u306a\u611f\u3058\u3067\u3001 \u6e96\u5099\u304c\u6574\u3063\u305f\u306e\u3067\u3001\u30b5\u30f3\u30d7\u30eb\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u9759\u7684\u578b\u4ed8\u3051\u3063\u307d\u304f\u30c7\u30b6\u30a4\u30f3\u3057\u306a\u304a\u3057\u3066\u307f\u307e\u3059\u3002 \u6b21\u306b\u5b9f\u969b\u306b\u578b\u691c\u67fb\u3092\u3057\u3066\u307f\u307e\u3059\u3002 \u3053\u308c\u3067User\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u306b\u6e21\u305b\u308b\u30c7\u30fc\u30bf\u306f\u3001TypeUser\u578b\u3060\u3051\u306b\u306a\u3063\u305f\u306f\u305a\u3067\u3059\u3002 \u78ba\u8a8d\u306e\u305f\u3081\u3001\u9593\u9055\u3063\u305f\u30c7\u30fc\u30bf\u578b\u3092\u6e21\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002 \u3042\u308b\u3079\u304d\u30d7\u30ed\u30d1\u30c6\u30a3\u304c\u7121\u3044\u3053\u3068\u3092\u8b66\u544a\u3057\u3066\u304f\u308c\u307e\u3057\u305f\uff01 \u540c\u3058\u3088\u3046\u306b\u3001\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u306e\u5404\u6240\u3067\u5fc5\u8981\u306a\u578b\u3092\u66f8\u3044\u3066\u3044\u304d\u3001\u6700\u7d42\u5f62\u306f\u3053\u3093\u306a\u611f\u3058\u306b\u306a\u308a\u307e\u3057\u305f\u3002<\/p>\n \u3053\u306e\u72b6\u614b\u3067 \u9759\u7684\u578b\u4ed8\u3051\u6700\u9ad8\u3068\u3044\u3046\u601d\u3044\u304b\u3089 \u500b\u4eba\u7684\u306b\u306f\u3001\u72ec\u81ea\u306e\u578b\u3092\u4f5c\u308b\u3068\u3053\u308d\u304b\u3089\u767a\u60f3\u3057\u305f\u65b9\u304c\u5408\u7406\u7684\u306a\u69cb\u9020\u306e\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u8a2d\u8a08\u3057\u3084\u3059\u3044\u3088\u3046\u306b\u611f\u3058\u3066\u3044\u308b\u306e\u3067\u3001\u696d\u52d9\u30b3\u30fc\u30c9\u3067\u3082\u7a4d\u6975\u7684\u306b\u53d6\u308a\u5165\u308c\u3066\u884c\u304d\u305f\u3044\u3068\u601d\u3063\u3066\u3044\u307e\u3059\u3002 \u4ee5\u4e0a\u3001\u53c2\u8003\u306b\u306a\u308c\u3070\u5e78\u3044\u3067\u3059<\/p>\n \u4eca\u56de\u3054\u7d39\u4ecb\u3057\u305f\u3088\u3046\u306a\u3001\u5408\u7406\u7684\u306a\u69cb\u9020\u306e\u30d3\u30b8\u30cd\u30b9\u30fb\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u958b\u767a<\/a>\u3092\u5fa1\u5e0c\u671b\u306e\u4f01\u696d\u69d8\u306f\u3001\u662f\u975eMMM\u306b\u3054\u76f8\u8ac7\u4e0b\u3055\u3044\u307e\u305b\uff01<\/p>\n \u30cf\u30a6\u30b9\u30fb\u30aa\u30d6\u30fb\u30ab\u30fc\u30c9\u3067\u5bdd\u4e0d\u8db3\u306e\u5c0f\u98fc\u3067\u3059\u3002 \u3069\u3046\u306a\u308b\u3093\u3067\u3059\u304b\u3001\u3042\u306e\u30a2\u30ec\u306f… \u3055\u3066\u3001\u6700\u8fd1\u500b\u4eba\u7684\u306bGolang\u3067\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u4f5c\u3063\u305f\u308a\u3001Haskell\u3092\u52c9\u5f37\u3057\u305f\u308a\u3057\u3066\u3044\u307e\u3059\u3002 \u3044\u305a\u308c\u3082\u9759\u7684\u578b\u4ed8\u3051\u306b\u3088\u308a\u3001\u5b9f\u884c\u524d\u306b\u578b\u30a8\u30e9\u30fc\u3092\u691c\u51fa\u53ef\u80fd\u306a\u8a00\u8a9e\u3067\u3059\u3002 \u79c1\u306f\u666e\u6bb5\u3001\u52d5\u7684\u578b\u4ed8\u3051\u8a00\u8a9e\u3067\u3042\u308bJavaScript\u3092\u4e3b\u306b\u66f8\u3044\u3066\u3044\u307e\u3059\u306e\u3067\u3001\u521d\u3081\u3053\u305d\u30d3\u30eb\u30c9\u6642\u306e\u30a8\u30e9\u30fc\u306b\u30e4\u30ad\u30e2\u30ad\u3057\u305f\u308a\u3057\u307e\u3057\u305f\u304c\u3001\u6163\u308c\u3066\u304f\u308b\u3068\u975e\u5e38\u306b\u5feb\u9069\u306b\u611f\u3058\u308b […]<\/p>\n","protected":false},"author":1,"featured_media":826,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[7],"tags":[77,78,174],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/posts\/256"}],"collection":[{"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/comments?post=256"}],"version-history":[{"count":0,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/posts\/256\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/media\/826"}],"wp:attachment":[{"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/media?parent=256"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/categories?post=256"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/tags?post=256"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}
\n\u3069\u3046\u306a\u308b\u3093\u3067\u3059\u304b\u3001\u3042\u306e\u30a2\u30ec\u306f...<\/p>\nGolang<\/code>\u3067\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u4f5c\u3063\u305f\u308a\u3001
Haskell<\/code>\u3092\u52c9\u5f37\u3057\u305f\u308a\u3057\u3066\u3044\u307e\u3059\u3002
\n\u3044\u305a\u308c\u3082\u9759\u7684\u578b\u4ed8\u3051<\/a>\u306b\u3088\u308a\u3001\u5b9f\u884c\u524d\u306b\u578b\u30a8\u30e9\u30fc\u3092\u691c\u51fa\u53ef\u80fd\u306a\u8a00\u8a9e\u3067\u3059\u3002
\n\u79c1\u306f\u666e\u6bb5\u3001\u52d5\u7684\u578b\u4ed8\u3051\u8a00\u8a9e\u3067\u3042\u308bJavaScript<\/code>\u3092\u4e3b\u306b\u66f8\u3044\u3066\u3044\u307e\u3059\u306e\u3067\u3001\u521d\u3081\u3053\u305d\u30d3\u30eb\u30c9\u6642\u306e\u30a8\u30e9\u30fc\u306b\u30e4\u30ad\u30e2\u30ad\u3057\u305f\u308a\u3057\u307e\u3057\u305f\u304c\u3001\u6163\u308c\u3066\u304f\u308b\u3068\u975e\u5e38\u306b\u5feb\u9069\u306b\u611f\u3058\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\u3002<\/p>\n
if typeof variable !== 'string' console.warn('\u578b\u304c\u9055\u3046')<\/code>\u306e\u3088\u3046\u306a\u30b3\u30fc\u30c9)\u304c\u4e0d\u8981\u306b\u306a\u308b\u3053\u3068\u4ee5\u5916\u306b\u3001\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u56fa\u6709\u306e\u30c7\u30fc\u30bf\u69cb\u9020\u3092\u578b\u3068\u3057\u3066\u5ba3\u8a00\u3059\u308b\u3053\u3068\u3067\u3001
\u4f55\u3092\u3059\u308b\u304b<\/code>\u3088\u308a\u3082
\u4f55\u3067\u3042\u308b\u304b<\/code>\u306b\u6ce8\u76ee\u3057\u305f\u8aad\u307f\u3084\u3059\u3044\u30b3\u30fc\u30c9\u3092\u66f8\u304f\u3053\u3068\u304c\u53ef\u80fd\u306b\u306a\u308b\u304b\u3089\u3067\u3059\u3002<\/p>\n
React.js<\/code>\u306b\u306f
PropType<\/code>\u3068\u3044\u3046\u578b\u30b7\u30b9\u30c6\u30e0\u3092\u5302\u308f\u305b\u308b\u3088\u3046\u306a\u4ed5\u7d44\u307f\u304c\u7528\u610f\u3055\u308c\u3066\u3044\u307e\u3059\u304c\u3001\u5b9f\u884c\u6642\u306e\u578b\u30a8\u30e9\u30fc\u691c\u51fa\u3067\u3059\u3057\u3001\u30ab\u30b9\u30bf\u30e0\u578b(\u306e\u3088\u3046\u306a\u3082\u306e)\u306f\u72ec\u81ea\u306e\u578b\u691c\u8a3c\u95a2\u6570\u3092\u7528\u610f\u3059\u308b\u3088\u3046\u306a\u3082\u306e\u3067\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306e\u767b\u5834\u4eba\u7269\u3092\u5ba3\u8a00\u3059\u308b\u3088\u306a\u4f7f\u3044\u65b9\u306f\u96e3\u3057\u304f\u3001\u4e0a\u8a18\u306e\u3088\u3046\u306a\u30e1\u30ea\u30c3\u30c8\u306f\u53d7\u3051\u306b\u304f\u3044\u5370\u8c61\u3067\u3059\u3002<\/p>\n
JavaScript<\/code>\u754c\u9688\u3067\u9759\u7684\u578b\u4ed8\u3051\u3092\u5c0e\u5165\u3059\u308b\u3068\u3057\u305f\u3089\u3001\u4ee5\u4e0b\u306e2\u3064\u306e\u30e9\u30a4\u30d6\u30e9\u30ea(\u30c8\u30e9\u30f3\u30b9\u30b3\u30f3\u30d1\u30a4\u30e9)\u304c\u30e1\u30b8\u30e3\u30fc\u306a\u9078\u629e\u80a2\u306a\u306e\u3067\u306f\u306a\u3044\u3067\u3057\u3087\u3046\u304b
\n(elm<\/code>\u306b\u3082\u9759\u7684\u578b\u4ed8\u3051\u306f\u3042\u308b\u3088\u3046\u3067\u3059\u304c\u3001\u30e1\u30b8\u30e3\u30fc\u306a\u9078\u629e\u80a2\u3068\u3057\u3066\u53d6\u308a\u5f97\u308b\u304b?\u3068\u3044\u3046\u3068...)<\/p>\n
\n
Angular2.x~<\/code>\u306e\u57fa\u76e4\u3068\u306a\u3063\u3066\u3044\u308b
TypeScript<\/code>\u3082\u6c17\u306b\u306a\u308b\u3068\u3053\u308d\u3067\u306f\u3042\u308a\u307e\u3059\u304c\u3001\u672c\u7a3f\u3067\u306f\u8efd\u3081\u306b\u59cb\u3081\u3089\u308c\u308b\u3068\u5642\u306e
Flow<\/code>\u3092\u6271\u3063\u3066\u307f\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n
Github-API<\/code>\u304b\u3089\u30e6\u30fc\u30b6\u306e\u30ea\u30b9\u30c8\u3092\u53d6\u3063\u3066\u304d\u3066\u3001\u30e6\u30fc\u30b6\u306e\u30b5\u30e0\u30cd\u30a4\u30eb\u3068\u540d\u524d\u3092\u63cf\u753b\u3059\u308b\u3001\u7c21\u5358\u306a\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002
\n\u6b21\u306b\u3053\u306e\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3078\u5b9f\u969b\u306bFlow<\/code>\u3092\u9069\u7528\u3059\u308b\u3053\u3068\u3067\u3001\u9759\u7684\u578b\u4ed8\u3051\u306e\u30e1\u30ea\u30c3\u30c8\u304c\u5f97\u3089\u308c\u308b\u304b\u3092\u691c\u8a3c\u3057\u3066\u307f\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n
\n<\/p>\n\u52d5\u7684\u578b\u4ed8\u3051\u306e\u30b5\u30f3\u30d7\u30eb<\/h2>\n
Flow<\/code>\u3092\u5c0e\u5165\u3057\u306a\u3044\u72b6\u614b\u306e\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002
\n\u8a71\u3092\u7c21\u5358\u306b\u3059\u308b\u305f\u3081\u306b\u3001Flux<\/code>\u7cfb\u306e\u4f55\u3084\u304b\u3084\u306f\u4f7f\u308f\u305a\u306b\u3001\u5b9f\u76f4\u306a
Props<\/code>\u30d0\u30b1\u30c4\u30ea\u30ec\u30fc\u306b\u3088\u308a\u30c7\u30fc\u30bf\u3092\u4f1d\u64ad\u3055\u305b\u307e\u3059\u3002
\n(\u5b9f\u884c\u6642\u306e\u578b\u30a8\u30e9\u30fc\u691c\u51fa\u306b\u3088\u308b\u6069\u6075\u306f\u3001\u672c\u7a3f\u306e\u4e3b\u984c\u304b\u3089\u5916\u308c\u308b\u305f\u3081PropType<\/code>\u306e\u5ba3\u8a00\u3082\u3057\u307e\u305b\u3093)<\/p>\n
import React, { Component } from 'react';\nimport ReactDOM from 'react-dom';\nimport 'whatwg-fetch';\n\nclass Root extends Component {\n constructor() {\n super()\n this.state = {\n users: []\n }\n }\n componentWillMount() {\n fetch('https:\/\/api.github.com\/users')\n .then(r=> r.json())\n .then(r=> this.setState({\n users: j.map(u=> ({\n name: u.login,\n img: u.avatar_url,\n })),\n }))\n .catch(e=> console.log(e))\n }\n render() {\n return <Users users={this.state.users}\/>\n }\n}\n\nclass Users extends Component {\n constructor() {\n super()\n }\n render() {\n return <ul>{this.props.users.map((user, i)=> <User key={i} user={user}\/>)}<\/ul>\n }\n}\n\nclass User extends Component {\n constructor() {\n super()\n }\n render() {\n const { user } = this.props;\n return (\n <li>\n <a href={`https:\/\/github.com\/${user.name}`}><img src={user.img} alt={user.name} \/><\/a>\n {user.name}\n <\/li>\n )\n }\n}\n\nReactDOM.render(<Root \/>, document.querySelector('#root'))<\/code><\/pre>\n
\nRoot<\/code>\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u306b\u30e6\u30fc\u30b6\u4e00\u89a7\u306e\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u3092\u6e21\u3057\u3066\u3001\u63cf\u753b\u3059\u308b\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3067\u3059\u3002
\n\u3053\u3053\u306bFlow<\/code>\u306b\u3088\u308b\u9759\u7684\u578b\u4ed8\u3051\u3092\u5c0e\u5165\u3057\u3066\u3044\u304d\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n
\u5c0e\u5165\u6e96\u5099<\/h2>\n
\nFlow<\/code>\u306e\u7279\u5fb4\u3068\u3057\u3066
CLI\u30c4\u30fc\u30eb\u306b\u3088\u308b\u578b\u691c\u67fb<\/code>\u3068
\u30d3\u30eb\u30c9\u6642\u306e\u578b\u5ba3\u8a00\u9664\u53bb<\/code>\u306b\u3088\u3063\u3066\u3001\u9759\u7684\u306a\u578b\u691c\u67fb\u3092\u3057\u3064\u3064\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u5b9f\u884c\u6642\u306b\u306f\u578b\u5ba3\u8a00\u306e\u5f71\u97ff\u3092\u6301\u305f\u306a\u3044\u3053\u3068\u304c\u6319\u3052\u3089\u308c\u307e\u3059\u3002
\n\u3053\u308c\u306b\u3088\u3063\u3066\u3001\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306e\u4efb\u610f\u306e\u7b87\u6240\u304b\u3089\u6bb5\u968e\u7684\u306b\u578b\u5ba3\u8a00\u306e\u6069\u6075\u3092\u5c0e\u5165\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u3001\u3068\u3044\u3046\u30b3\u30f3\u30bb\u30d7\u30c8\u306e\u3088\u3046\u3067\u3059\u3002<\/p>\n\n
\nFlow is a gradual type system. Any parts of your program that are dynamic in nature can easily bypass the type checker, so you can mix statically typed code with dynamic code.<\/p>\n<\/blockquote>\n\u578b\u691c\u67fb\u306e\u305f\u3081\u306e\u30e2\u30b8\u30e5\u30fc\u30eb<\/code>\u3068
\u578b\u5ba3\u8a00\u9664\u53bb\u306e\u305f\u3081\u306e\u30e2\u30b8\u30e5\u30fc\u30eb<\/code>\u306e2\u7a2e\u985e\u306e\u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n
# \u578b\u691c\u67fb\u306e\u305f\u3081\u306e\u30e2\u30b8\u30e5\u30fc\u30eb(Flow\u306e\u672c\u4f53\u3068\u30b3\u30de\u30f3\u30c9\u30e9\u30a4\u30f3\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30fc\u30b9)\nnpm install --save flowtype flow-bin\n\n# babel\u306b\u3088\u308b\u30d3\u30eb\u30c9\u6642\u306b\u578b\u5ba3\u8a00\u3092\u9664\u53bb\u3059\u308b\u305f\u3081\u306e\u30d7\u30e9\u30b0\u30a4\u30f3\nnpm install --save babel-plugin-transform-flow-strip-types<\/code><\/pre>\n
babel<\/code>+
browserify<\/code>\u3067\u30d3\u30eb\u30c9\u3059\u308b\u60f3\u5b9a\u3067\u3001\u4f9d\u5b58\u30e2\u30b8\u30e5\u30fc\u30eb\u306f\u3053\u3093\u306a\u611f\u3058\u306b\u3057\u307e\u3057\u305f\u3002<\/p>\n
{\n "babel": "^6.5.2",\n "babel-plugin-transform-flow-strip-types": "^6.7.0",\n "babel-plugin-transform-react-jsx": "^6.7.4",\n "babel-plugin-transform-class-properties": "^6.6.0",\n "babel-preset-es2015": "^6.6.0",\n "babelify": "^7.2.0",\n "browserify": "^13.0.0",\n "flow-bin": "^0.22.1",\n "flowtype": "^1.0.0",\n "react": "^0.14.7",\n "react-dom": "^0.14.7",\n "whatwg-fetch": "^0.11.0"\n}<\/code><\/pre>\n
.babelrc<\/code>\u306e\u8a2d\u5b9a\u306f\u3053\u3093\u306a\u611f\u3058\u3067\u3059<\/p>\n
\n{\n "presets": [\n "es2015"\n ],\n "plugins": [\n "transform-react-jsx",\n "transform-class-properties",\n "transform-flow-strip-types"\n ]\n}<\/code><\/pre>\n
props\/state<\/code>\u306e\u578b\u691c\u67fb\u3092\u884c\u3044\u305f\u3044\u306e\u3067\u3001
[babel-plugin-transform-class-properties](https:\/\/www.npmjs.com\/package\/babel-plugin-transform-class-properties)<\/code>\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n
npm run flow<\/code>\u3067\u578b\u691c\u67fb\u3092\u3001
npm run browserify<\/code>\u3067\u30d3\u30eb\u30c9\u3092\u305d\u308c\u305e\u308c\u5b9f\u884c\u3057\u307e\u3059\u3002<\/p>\n
{\n "flow": "$(npm bin)\/flow",\n "browserify": "$(npm bin)\/browserify app.js -t babelify -o bundle.js",\n "build": "npm run flow && npm run browserify"\n}<\/code><\/pre>\n
Flow<\/code>\u7528\u306e\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb
.flowconfig<\/code>\u3092\u3001\u516c\u5f0f\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u306e\u624b\u9806<\/a>\u3092\u53c2\u8003\u306b\u751f\u6210\u3057\u3066\u3001\u578b\u691c\u67fb\u306e\u5bfe\u8c61\u30d5\u30a1\u30a4\u30eb\u306b
@flow<\/code>\u3092\u30b3\u30e1\u30f3\u30c8\u30a2\u30a6\u30c8\u3057\u3066\u8a18\u8ff0\u3057\u307e\u3059\u3002
\n\u30c7\u30d5\u30a9\u30eb\u30c8\u3060\u3068node_modules<\/code>\u3082\u691c\u67fb\u3057\u306b\u884c\u3063\u3066\u3057\u307e\u3046\u306e\u3067\u3001\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u306e
[ignore]<\/code>\u306b\u66f8\u3044\u3066\u304a\u3044\u305f\u65b9\u304c\u3044\u3044\u3067\u3057\u3087\u3046\u3002<\/p>\n
[ignore]\nbundle.js\n.*\/node_modules\/fbjs\/*\n[include]\n\n[libs]\ndeclare.js\n[options]\nesproposal.class_instance_fields=enable\nesproposal.class_static_fields=enable<\/code><\/pre>\n
\u72ec\u81ea\u578b\u306e\u30c7\u30b6\u30a4\u30f3<\/h2>\n
\n\u3053\u306e\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3067\u767b\u5834\u3059\u308b\u4e3b\u306a\u30c7\u30fc\u30bf\u578b\u306b\u306f\u30e6\u30fc\u30b6\u306e\u540d\u524d\u3068\u753b\u50cf\u3092\u6301\u3063\u305f\u30c7\u30fc\u30bf<\/code>\u3068
\u30e6\u30fc\u30b6\u306e\u914d\u5217<\/code>\u304c\u3042\u308b\u3088\u3046\u3067\u3059\u306e\u3067\u3001\u3053\u3093\u306a\u611f\u3058\u3067\u5ba3\u8a00\u3057\u3066\u307f\u307e\u3059\u3002<\/p>\n
\/\/ \u30e6\u30fc\u30b6\u306e\u540d\u524d\u3068\u753b\u50cf\u3092\u6301\u3063\u305f\u30c7\u30fc\u30bf\u578b\ntype TypeUser = {\n name: string;\n img: string;\n}\n\n\/\/ \u30e6\u30fc\u30b6\u306e\u914d\u5217\ntype TypeUsers = Array<TypeUser>;<\/code><\/pre>\n
\nTypeUser\u578b\u306fUser\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u306eprops<\/code>\u3068\u3057\u3066\u4f7f\u308f\u308c\u307e\u3059\u306e\u3067\u3001User\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u306e
props<\/code>\u30d7\u30ed\u30d1\u30c6\u30a3\u306b\u578b\u6307\u5b9a\u3092\u3057\u307e\u3059\u3002<\/p>\n
class User extends Component {\n props: {\n user: TypeUser;\n };\n static defaultProps = {\n user: { name: '', img: '' },\n };\n \/*... *\/\n}<\/code><\/pre>\n
\nnpm run flow<\/code>\u3067\u578b\u691c\u67fb\u3092\u3057\u3066\u307f\u308b\u3068\u3001
No errors!<\/code>\u3068\u8868\u793a\u3055\u308c\u308b\u306f\u305a\u3067\u3059\u3002<\/p>\n
\nTypeUser\u578b<\/code>\u304c\u6301\u3063\u3066\u3044\u308b\u306f\u305a\u306e
name\/img<\/code>\u30d7\u30ed\u30d1\u30c6\u30a3\u3092\u3044\u305a\u308c\u3082\u6301\u3063\u3066\u3044\u306a\u3044\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u6e21\u3057\u3066\u307f\u307e\u3059<\/p>\n
class Users extends Component {\n \/*... *\/\n render() {\n \/\/ return <ul>{this.props.users.map((user, i)=> <User key={i} id={i} user={user}\/>)}<\/ul>\n return <ul>{[{noname: '', noimg: ''}].map((user, i)=> <User key={i} user={user}\/>)}<\/ul>\n }\n}<\/code><\/pre>\n
app.js:57\n 57: user: TypeUser;\n ^^^^^^^^ property `img`. Property not found in\n 53: render = ()=> (<ul>{[{noname: '', noimg: ''}].map((u, i)=> <User key={i} user={u}\/>)}<\/ul>);\n ^ object literal\n\napp.js:57\n 57: user: TypeUser;\n ^^^^^^^^ property `name`. Property not found in\n 53: render = ()=> (<ul>{[{noname: '', noimg: ''}].map((u, i)=> <User key={i} user={u}\/>)}<\/ul>);\n ^ object literal\n\n\nFound 2 errors<\/code><\/pre>\n
\n\u30d6\u30e9\u30a6\u30b6\u3067\u5b9f\u884c\u3059\u308b\u524d\u306b\u578b\u30a8\u30e9\u30fc\u3092\u691c\u51fa\u3057\u3066\u304f\u308c\u308b\u306e\u3067\u3001\u5b89\u5fc3\u3057\u3066\u958b\u767a\u304c\u3067\u304d\u305d\u3046\u3067\u3059<\/p>\n\/\/ @flow\nimport React, { Component } from 'react';\nimport ReactDOM from 'react-dom';\nimport 'whatwg-fetch';\n\ntype TypeUser = {\n name: string;\n img: string;\n}\n\ntype UsersType = Array<TypeUser>;\n\nclass Root extends Component {\n state: {\n users: UsersType\n };\n constructor() {\n super()\n this.state = {\n users: [],\n }\n }\n componentWillMount() {\n fetch('https:\/\/api.github.com\/users')\n .then(r=> r.json())\n .then(j=> {\n this.setState({\n users: j.map((u): TypeUser => ({\n name: u.login,\n img: u.avatar_url,\n })),\n })\n })\n .catch(e=> console.log(e))\n }\n render() {\n return <Users users={this.state.users}\/>\n }\n}\n\nclass Users extends Component {\n props: {\n users: UsersType;\n };\n static defaultProps = {\n users: []\n };\n constructor() {\n super()\n }\n render() {\n return <ul>{this.props.users.map((user, i)=> <User key={i} user={user}\/>)}<\/ul>\n }\n}\n\nclass User extends Component {\n props: {\n user: TypeUser;\n };\n static defaultProps = {\n user: { name: '', img: '' },\n };\n constructor() {\n super()\n }\n render() {\n const { user } = this.props;\n return (\n <li>\n <a href={`https:\/\/github.com\/${user.name}`}><img src={user.img} alt={user.name} \/><\/a>\n {user.name}\n <\/li>\n )\n }\n}\n\nReactDOM.render(<Root \/>, document.querySelector('#root'))<\/code><\/pre>\n
npm run browserify<\/code>\u30b3\u30de\u30f3\u30c9\u3092\u6253\u3064\u3068\u3001
transform-flow-strip-types<\/code>\u304c\u578b\u5ba3\u8a00\u3092\u9664\u53bb\u3057\u3066\u304b\u3089
bundle<\/code>\u30d5\u30a1\u30a4\u30eb\u3092\u751f\u6210\u3067\u304d\u307e\u3059\u3002
\n\u9759\u7684\u578b\u4ed8\u3051\u306e\u6069\u6075\u3092\u53d7\u3051\u3064\u3064\u3001\u5b9f\u884c\u30b3\u30fc\u30c9\u306b\u306f\u5f71\u97ff\u304c\u7121\u3044\u306e\u304c\u826f\u3044\u3067\u3059\u306d\u3002<\/p>\n\u307e\u3068\u3081<\/h2>\n
Flow<\/code>\u3092\u8a66\u3057\u3066\u307f\u307e\u3057\u305f\u304c\u3044\u304b\u304c\u3060\u3063\u305f\u3067\u3057\u3087\u3046\u304b\u3002
\n\u65e2\u5b58\u306e\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306e\u4efb\u610f\u306e\u7b87\u6240\u304b\u3089\u3001lint<\/code>\u30c4\u30fc\u30eb\u306e\u3088\u3046\u306b\u5c0f\u3055\u304f\u6c17\u8efd\u306b\u4f7f\u3044\u59cb\u3081\u3089\u308c\u308b\u306e\u304c\u826f\u3044\u3067\u3059\u306d\u3002<\/p>\n
\n\u30c0\u30e1\u305d\u3046\u3060\u3063\u305f\u3089\u3059\u3050\u96e2\u308c\u3089\u308c\u308b\u8efd\u3055\u3082\u3046\u308c\u3057\u3044\u3068\u3053\u308d\u3067\u3059\u3002<\/p>\n\u53c2\u8003<\/h2>\n
\n