flow check
I install flow locally, and add "flowcheck": flow check to package.json, and I run npm run flowcheck, then I got blow, but if I just run ./node_modules/.bin/flow check , its totally fine without npm error log
12: total([1, 2, 3, 'Hello']);
^^^^^^^^^^^^^^^^^^^^^^^^^ function call
12: total([1, 2, 3, 'Hello']);
^^^^^^^ string. This type is incompatible with
3: function total(numbers: Array
Found 1 error
npm ERR! Darwin 16.1.0
npm ERR! argv "/usr/local/Cellar/node/7.1.0/bin/node" "/usr/local/bin/npm" "run-script" "flowcheck"
npm ERR! node v7.1.0
npm ERR! npm v3.10.9
npm ERR! code ELIFECYCLE
npm ERR! [email protected] flowcheck: flow check
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the [email protected] flowcheck script 'flow check'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the es6 package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! flow check
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs es6
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls es6
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request: npm ERR! /Users/zhumaohua/WorkSpace/Es6/npm-debug.log
@rookiezmh
this will work with your array:
const validTotal = [1, 2, 3, 'Hello'];
// Function takes an array of number or strings and returns an array of number of strings
function total(numbers: Array<number | string>): Array<number | string> {
return numbers
}
total(validTotal);
If you want total to accept only numbers use below:
const validNumbers = [1, 2, 3];
const invalidNumbers = [1, 2, 3, 'Hi'];
// Function takes an array of numbers, and returns a single number
function total(numbers: Array<number>): number {
return numbers.reduce(
(acc, curr) => acc + curr, 0
)
}
total(validNumbers);
total(invalidNumbers); // error
sorry,but maybe I didn't express myself clearly. My issue is why after I ran "npm run flowcheck", I got the npm err info. I know my code could not pass the flow check, but what's with the npm error info? I ran "./node_moudlues/.bin/flow check" directly is fine, it just gave me the info of flow check, not with the npm err info.
@rookiezmh this is just how npm works when script exists with error code
@vkurchatkin I agree somewhat with @rookiezmh we're all aware of the error NPM exit but it creates unnecessary npm logs and is a strange behavior coming from a type checker. All is well when no errors but there should be a way to handle errors without exiting out to NPM and create a log.
If you want to ignore exit code then you can add || true to your command
I think we can close this one
cloesed