I have the following code: a function which returns an option from an array. The options could be strings or regexes, and the return value will follow suit.
const pick = (options: Array<string | RegExp>): string | RegExp => options[Math.floor(Math.random() * options.length)]; const myOptions = ['hello', 'goodbye'] const randomId: string = pick(myOptions);
This raises this error:
Cannot assign
pick(...)
torandomId
becauseRegExp
[1] is incompatible with string [2].Flow(incompatible-type)
Why is this?
https://stackoverflow.com/questions/67326795/why-does-flow-assume-this-function-returns-a-regexp April 30, 2021 at 08:42AM
没有评论:
发表评论