Last active
June 10, 2018 15:34
-
-
Save TakahashiIkki/4a915f752d6897a67732738a715326f2 to your computer and use it in GitHub Desktop.
初心者が学ぶflowtype入門 Ver.1.0 ref: https://qiita.com/ikkitang/items/8c22b93fc4d7ca166495
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ignore] | |
+ .*/node_modules/.* | |
[include] | |
[libs] | |
[lints] | |
[options] | |
[strict] | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// @flow | |
let message = 'flowType'; | |
message = 2; | |
console.log("Hello! " + message); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let value : number = 1; | |
let str : string = "1"; | |
if (value == str) { | |
console.log("同じ"); | |
} else { | |
console.log("違う"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# node 環境を作成 | |
$ npm init -y | |
# flowtypeをinstall | |
$ npm install --save flowtype flow-bin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ npm run-script flow check | |
Error ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ src/app.js:5:5 | |
Cannot compare number [1] to string [2]. | |
[1] 2│ let value : number = 1; | |
[2] 3│ let str : string = "1"; | |
4│ | |
5│ if (value == str) { | |
6│ console.log("同じ"); | |
7│ } else { | |
8│ console.log("違う"); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ルートディレクトリ上で実行. | |
$ npm run-script flow check | |
> [email protected] flow /Users/hogehoge/flowtype-sample | |
> flow "check" | |
Found 0 errors |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ node src/app.js | |
Hello! Node.js × flowtype |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
~~ | |
Error ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ src/app.js:4:11 | |
Cannot assign 2 to message because number [1] is incompatible with string [2]. | |
1│ // @flow | |
2│ | |
[2] 3│ let message: string = 'flowType'; | |
[1] 4│ message = 2; | |
5│ console.log("Hello! " + message); | |
〜〜 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "flowtype-sample", | |
"version": "1.0.0", | |
"description": "", | |
"main": "index.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1", | |
+ "flow": "flow" | |
}, | |
"keywords": [], | |
"author": "", | |
"license": "ISC", | |
"dependencies": { | |
"flow-bin": "^0.74.0", | |
"flowtype": "^2.0.0" | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment