Skip to content

Type error with Option API #415

Closed
Closed
@sxzz

Description

@sxzz
<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;
                     ~

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions