Redux how to use "compose" with Typescript

I have a little problem using the build function in Typescript, I always get errors. Type definition in .d.ts is also rather confusing. For example:

type Props = { t: number }; 
const foo = (props: {}) => <div {...props} />;
const moo = (props: Props) => <div {...props} />;
const bar = (props: Props) => <div {...props} />;
const Dar = compose(foo, moo)(bar);

const Test = () => <Dar />;

It has a few problems. He complains that "bar" does not have the parameter "foo" (which it really has).

Also, I cannot use it, since Dar is evaluated as JSX.Element, not a stateless function. Any IDEA with a possible example of using composition in Typescript?

Thanks.

+9
source share
2 answers

compose is a function that combines two functions, assuming that the output type of the first function matches the input type of the second function.

const compose = (f,g) => x => f(g(x))

, , bar ( Props JSX.Element) moo, Props JSX.Element, foo.

, moo Props JSX.Element, Props

" ", , Typescript,

const bar: React.FunctionComponent<Props> = (x: Props) => <div {...props} />;
0

TypeScript , compose .

, , , flow.

0

All Articles