Skip to content

[Vue2.7] A type error. method can't be called in option "data" #12944

Open
@timongh

Description

@timongh

Version

2.7.14

Reproduction link

github.com

Steps to reproduce

  1. run pnpm install(or use npm, yarn)
  2. run pnpm type-check(actual command is vue-tsc --noEmit)

What is expected?

no error

What is actually happening?

An error was reported: The method in option methods could not be found in the option data

src/main.ts:6:19 - error TS2339: Property 'method1' does not exist on type 'CreateComponentPublicInstance<{}, {}, {}, {}, {}, ComponentOptionsMixin,
 ComponentOptionsMixin, {}, {}, {}, false, OptionTypesType<{}, {}, {}, {}, {}, {}>, {}, {}, {}, {}, {}, {}>'.

6       data1: this.method1(),
                    ~~~~~~~

The main code in the repository is:

defineComponent({
  data() {
    return {
      data1: this.method1(),
    }
  },
  methods: {
    method1(): number {
      return 1
    }
  }
})

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