apollo icon indicating copy to clipboard operation
apollo copied to clipboard

[3.1.0] computed properties typed wrongly in reactive variables with Vue 2.7.10

Open tminich opened this issue 3 years ago • 1 comments

Describe the bug After updating to Vue 2.7.10 from 2.7.8 computed properties on this in a reactive variables definition are no longer typed correctly. The apparent type is of the method defining the computed property and not it's return value.

To Reproduce Example:

<template>
    <div>Test</div>
</template>

<script lang="ts">
    import {defineComponent} from 'vue'

    type Test = 'a' | 'b'
    interface Variables {
        test: Test[]
    }

    export default defineComponent({
        apollo: {
            test: {
                variables(): Variables {
                    return {
                        test: this.a_b // Error here
                    }
                }
            }
        },
        computed: {
            a_b(): Test[] {
                return []
            },
        },
    })
</script>

Causes the Error

TS2322: Type '() => Test[]' is not assignable to type 'Test[]'.

Expected behavior No error.

Versions vue: 2.7.10 vue-apollo: 3.1.0 apollo-client: 2.6.10

tminich avatar Aug 24 '22 12:08 tminich

I am also experiencing this issue.

[email protected]
[email protected]
[email protected]
[email protected]

I notice if we use Vue.extend I do not have the issue but when I use defineComponent we do. Which is problematic because we are in the process of updating our whole app to defineComponent

JordanMajd avatar Sep 17 '22 06:09 JordanMajd