by phpnode · 9y ago · 0 comments
It looks like this:
import t from 'flow-runtime';
const makeUpperCase = t.pattern(
(input: string) => input.toUpperCase(),
(input: number) => input
);
console.log(makeUpperCase("foo bar"));
console.log(makeUpperCase(123));
console.log(makeUpperCase(false)); // throws
[0] https://codemix.github.io/flow-runtime/#/docs/pattern-matchi... const makeUpperCase = t.pattern(
(input: string) => input.toUpperCase(),
(input: number) => '' + input
);
Otherwise you get odd behaviours like: makeUpperCase('1') + makeUpperCase('1') = '11' (probably what you want)
makeUpperCase(1) + makeUpperCase(1) = 2 (probably not what you want)In other words, the result of "makeUppercase" should be a string, not a number.