Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type error with Option API #415

Closed
sxzz opened this issue Aug 25, 2021 · 2 comments
Closed

Type error with Option API #415

sxzz opened this issue Aug 25, 2021 · 2 comments
Labels
question Further information is requested

Comments

@sxzz
Copy link
Member

sxzz commented Aug 25, 2021

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

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

export default defineComponent({
  data() {
    return {
      a: {
        b: '',
      },
    };
  },
  computed: {
    length() {
      return this.a.b;
      /**
       * 类型“CreateComponentPublicInstance<{} | {}, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, EmitsOptions, {} | {}, {}, false, ... 6 more ..., {}>”上不存在属性“a”。
  类型“{ $: ComponentInternalInstance; $data: {}; $props: {} | {}; $attrs: Data; $refs: Data; $slots: Readonly<InternalSlots>; ... 7 more ...; $watch(source: string | Function, cb: Function, options?: WatchOptions<...> | undefined): WatchStopHandle; } & ... 4 more ... & ComponentCustomProperties”上不存在属性“a”。ts(2339)
       */
    },
  },
});
</script>
src/test.vue:18:19 - error TS2339: Property 'a' does not exist on type 'CreateComponentPublicInstance<{} | {}, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, EmitsOptions, {} | {}, {}, false, ... 6 more ..., {}>'.
  Property 'a' does not exist on type '{ $: ComponentInternalInstance; $data: {}; $props: {} | {}; $attrs: Data; $refs: Data; $slots: Readonly<InternalSlots>; ... 7 more ...; $watch(source: string | Function, cb: Function, options?: WatchOptions<...> | undefined): WatchStopHandle; } & ... 4 more ... & ComponentCustomProperties'.

18       return this.a.b;
                     ~
@johnsoncodehk
Copy link
Member

This is correct report, you can reproduce this error in *.ts file with same code.

Vue Land TS discord server may help.

@sxzz
Copy link
Member Author

sxzz commented Aug 25, 2021

Thanks.

Solution: vuejs/vue#8721 (comment)

@johnsoncodehk johnsoncodehk added question Further information is requested and removed upstream labels Aug 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants