Skip to content

[2.7.x] [typescript] Type inference breaks under specific circumstances #12902

@last-partizan

Description

@last-partizan

Version

2.7.14

Reproduction link

github.com

Or create this file in minimal vue-ts (v2) project

import {defineComponent} from "vue";

import App from "./App.vue";

export default defineComponent({
  // comment next line, and it works fine.
  components: {App},
  // or uncomment next line, and it works fine
  //props: {},
  data() {
    return {};
  },
  provide(): any {
    return {
      fetchData: this.fetchData,
    };
  },
  created() {
    this.fetchData();
  },
  methods: {
    fetchData() {
      throw new Error("Not implemented.");
    },
  },
});

Steps to reproduce

Clone example repo, run pnpm install, run pnpm vue-tsc

What is expected?

No errors.

What is actually happening?

src/broken-method-type.ts:15:23 - error TS2339: Property 'fetchData' does not exist on type 'CreateComponentPublicInstance ...

It works if you remove components: ... line, or add empty props: {}.

(This is continuation of #12628 which is not fixed completely, or happened again, in my project it was working with vue-tsc<1.0, but happened again after update)

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