I'm encountering an issue with omit in typescript. Whenever I attempt to omit commandId from TMutationVariables, it triggers a TS error:
TS2345: Argument of type 'Pick<TMutationVariables, Exclude<keyof TMutationVariables, "commandId">> & { commandId: string; }' is not assignable to parameter of type 'TMutationVariables'. 'Pick<TMutationVariables, Exclude<keyof TMutationVariables, "commandId">> & { commandId: string; }' is assignable to the constraint of type 'TMutationVariables', but 'TMutationVariables' could be instantiated with a different subtype of constraint '{ commandId: string; }'.
export function createQueryWithSubscription<TMutationVariables extends {commandId: string}>(
query: string,
): (variables: Omit<TMutationVariables, "commandId">) => any {
const sendQuery = (changes: TMutationVariables): any =>
gqlCommand<TMutationVariables>(
query, changes as any
);
return function processQueryWithSubscription(
variables
) {
return async (dispatch: any) => {
const commandId = generateUuid();
//error occurs in declaration BELOW
const completedVariables: TMutationVariables = {
...variables,
commandId
};
const commandFinished = await dispatch(sendQuery(completedVariables));
};
};
}
I have a type generated from graphql schema (which includes commandId for subscription), but externally I require all variables produced from this schema except commandId (since I combine commandId in the process function).
Any assistance would be greatly appreciated. Thank you.