我是自由点风格的忠实拥护者,它结合了recompose,lodash / fp和react。最近切换到打字稿,发现很难省略带有通用字符E.G.的多余功能包装:
import * as QueryAllExercises from '@ease/api/GraphQL/queryGetAllExercises.gql';
import { getOr } from 'lodash/fp';
import { graphql } from 'react-apollo';
import { compose } from 'recompose';
import { Exercise } from 'src/Exercises';
interface WithExercises {
exercises: Exercise[];
};
const withExercises = <TOutter extends object>(Comp: React.ComponentType<TOutter & WithExercises>) => compose<TOutter & WithExercises, TOutter>(
graphql(
QueryAllExercises,
{
options: {
fetchPolicy: 'cache-and-network',
},
props: resp => ({ exercises: getOr([], 'data.listExercises.items', resp) }),
},
),
)(Comp);
export default withExercises;
想知道是否有另一种方式可以输入此内容,而没有额外的箭头功能,例如(显然不起作用):
import * as QueryAllExercises from '@ease/api/GraphQL/queryGetAllExercises.gql';
import { getOr } from 'lodash/fp';
import { graphql } from 'react-apollo';
import { compose } from 'recompose';
import { Exercise } from 'src/Exercises';
interface WithExercises {
exercises: Exercise[];
};
const withExercises = <TOutter>compose<TOutter & WithExercises, TOutter>(
graphql(
QueryAllExercises,
{
options: {
fetchPolicy: 'cache-and-network',
},
props: resp => ({ exercises: getOr([], 'data.listExercises.items', resp) }),
},
),
);
export default withExercises;