Skip to content

useMutation | Typescript generics improvements #1596

@woozie

Description

@woozie

Describe the bug
Please correct me if i'm using useMutation incorrectly but there are no good examples in the documentation

To Reproduce
Just write any mutation with generics

const {
  onDone: onSettingsUpdated,
  onError: onSettingsUpdateFailed,
  mutate: submitSettings,
} = useMutation<{
  settings: IProjects.ProjectSettings
}>(UpdateProjectSettingsMutation, { fetchPolicy: 'no-cache' })

onSettingsUpdated(({ data: { settings } }) => {
  toast.success(t('settings.notifications.settingsSaved'))
})

and in line

onSettingsUpdated(({ data: { settings } }) => {

compilation failed

src/components/views/ProjectSettingsView.vue:54:30 - error TS2339: Property 'settings' does not exist on type '{ settings: ProjectSettings; } | null | undefined'.

Expected behavior
No compilation errors

Versions
vue: 3.5.17
@vue/apollo-composable: 4.2.2
@vue/apollo-option: 4.2.2
@apollo/client: 3.3.18

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions