使用下面的issue on GitHub我能够使一个突变与Typescript一起工作。但我没有找到在同一组分中使用2个突变的方法。
mutate()中只有一个this.props函数。
我们必须如何输入组件才能让它理解传递给graphql的name选项?

graphql<ContainerProps, {}, string, ContainerProps>(gql`... `, { name: 'deleteData' });
graphql<ContainerProps, {}, string, ContainerProps>(gql`...`, { name: 'createData' });

编辑:
如果这2个突变具有相同的参数名(例如,string命名为cc>),我们真的需要将这些参数包在一个显式类型中吗?
编辑2:
当我宣布2个突变为“cc>”时,我有一个例外:
类型错误:this.props.mutate不是函数
如果我只声明一个突变(没有名称选项),它的工作正常。

最佳答案

基于miro lehtonen提供的链接,这里是对我有用的。

type MutationProps = {
    create: MutationFunc<IResponse, ICreateVariables>;
    delete: MutationFunc<IResponse, IDeleteVariables>;
};

type ContainerProps = OtherQueryProps & MutationProps;

const withCreate =
    graphql<ContainerProps, IResponse, ICreateVariables, ContainerProps>(
        CreateMutation,
        {
            // tslint:disable-next-line:no-any
            props: ({ mutate, ...rest }): any => ({
                ...rest,
                create: mutate
            })
        });

删除变异的代码相同。
代码正在工作,但我不喜欢其中有any。我没有找到正确的道具类型,我认为我没有返回正确的类型(尽管它工作正常)。欢迎提出任何建议(关于如何删除any)。

07-26 01:29