Reputation: 28770
I have the following functions:
const safeNull = fn => (txt: string): string => (isNil(txt) ? '' : fn(txt));
export const stripSpaces: Function = safeNull(txt => txt.replace(/\s/g, ''));
export const safeTrim: Function = safeNull(txt => txt.trim());
How do I say that stripSpaces
and safeTrim
return strings.
Upvotes: 1
Views: 289
Reputation: 1506
Your safeNull
function is typed to return a function that returns a string.
So all you have to do is remove those Function
types from stripSpaces
and safeTrim
.
Flow will infer that they return strings, because of safeNull
return type.
const safeNull = fn => (txt: string): string => (isNil(txt) ? '' : fn(txt));
export const stripSpaces = safeNull(txt => txt.replace(/\s/g, ''));
export const safeTrim = safeNull(txt => txt.trim());
You could also explicitly define their types, if you prefer, like so:
const safeNull = fn => (txt: string): string => (isNil(txt) ? '' : fn(txt));
export const stripSpaces: string => string = safeNull(txt => txt.replace(/\s/g, ''));
export const safeTrim: string => string = safeNull(txt => txt.trim());
Upvotes: 1