//@flow //數字 functionflow1(x:number){ console.log(x); } flow1(2); //字符串 functionflow2(x:string){ console.log(x); } flow2("xxx"); //可選參數 functionflow3(x:?string){ console.log(x); } flow3(); //多個值 functionflow4(x:"a"|"b"|"c"){ console.log(x); } flow3("a"); //任意值 functionflow5(y:any){ console.log(y); } flow3("a"); //數組 let arr:Array<boolean>=[true,false,true];
(注意⚠️:你須要確保你有一個可運行的webpack配置,同時在module.rules配置項中引入了babel-loader解析全部js文件)html
npm install @babel/plugin-transform-flow-strip-types
{ "plugins":[ "transform-flow-strip-types" ] }
npm install -g flow-bin
"scripts":{ "start":"flow check src && node ./server.js", }
//@flow functionflow1(x:number){ console.log(x); } //flow函數 flow1(2); //普通函數 functioncommon(a){ console.log(a); } common(1);
import {A,B,C,D,E} from‘lib’
import{
A,
B,
C,
D,
E
} from ‘lib’
yarn prettier --write './src/**/*.js' './src/**/*.jsx’
3.1 運行 npm init: 先初始化下npm空間 3.2 運行 npm i eslint, 安裝eslint 3.3 運行 eslint --init:初始化eslint
{ "env":{ "browser":true, "es6":true }, "extends":[ "eslint:recommended", "plugin:@typescript-eslint/eslint-recommended" ], "globals":{ "Atomics":"readonly", "SharedArrayBuffer":"readonly" }, "parser":"@typescript-eslint/parser", "parserOptions":{ "ecmaVersion":2018, "sourceType":"module" }, "plugins":["@typescript-eslint"], "rules":{ "semi": ["error","always"], "quotes":["error","double"] } }
"env":{ "browser":true,//瀏覽器環境 "node":true,//Node環境 "es6":true,//es6語法 "commonjs":true,//commonjs "worker":true//webwork相關語法 },
"globals":{ "Atomics":"readonly", "SharedArrayBuffer":"readonly" },
"parser": "@typescript-eslint/parser」,
"rules":{ "no-console":1 }
0:不報錯,不警告 1:警告但不報錯 2:報錯
"extends":[ "eslint:recommended", "plugin:@typescript-eslint/eslint-recommended" ]
"plugins":["react」]
ESLint was installed locally. We recommend using this local copy instead of your globally-installed copy