Skip to content

Instantly share code, notes, and snippets.

@TakahashiIkki
Last active June 10, 2018 15:34
Show Gist options
  • Save TakahashiIkki/4a915f752d6897a67732738a715326f2 to your computer and use it in GitHub Desktop.
Save TakahashiIkki/4a915f752d6897a67732738a715326f2 to your computer and use it in GitHub Desktop.
初心者が学ぶflowtype入門 Ver.1.0 ref: https://qiita.com/ikkitang/items/8c22b93fc4d7ca166495
[ignore]
+ .*/node_modules/.*
[include]
[libs]
[lints]
[options]
[strict]
// @flow
let message = 'flowType';
message = 2;
console.log("Hello! " + message);
let value : number = 1;
let str : string = "1";
if (value == str) {
console.log("同じ");
} else {
console.log("違う");
}
# node 環境を作成
$ npm init -y
# flowtypeをinstall
$ npm install --save flowtype flow-bin
$ 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("違う");
# ルートディレクトリ上で実行.
$ npm run-script flow check
> [email protected] flow /Users/hogehoge/flowtype-sample
> flow "check"
Found 0 errors
$ node src/app.js
Hello! Node.js × flowtype
~~
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);
〜〜
{
"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