Skip to content

Vue.extend return type error TS2322 with 4.6.2 #48089

Closed

Description

Bug Report

🔎 Search Terms

vue ts2322 could be instantiated with an arbitrary type

🕗 Version & Regression Information

Versions that exhibits the undesired behavior: 4.6.0-beta, 4.6.1-rc, 4.6.2, next
Version that works: 4.5.5

  • This changed between versions 4.5.5 and 4.6.2

⏯ Playground Link

The playground doesn't support 4.6.2 or external packages (Vue in this case) as far as I can see.

💻 Code

package.json

{
  "name": "vue-ts",
  "version": "1.0.0",
  "devDependencies": {
    "typescript": "^4.6.2",
    "vue": "^2.6.14"
  }
}

tsconfig.json

{
    "include": [
        "./src/*.ts"
    ]
}

src/file.ts

import Vue from "vue"
import { ThisTypedComponentOptionsWithRecordProps } from "vue/types/options"
import { ExtendedVue } from "vue/types/vue"

export function defineComponent<
    V extends Vue,
    Data,
    Methods,
    Computed,
    Props
    >(
    options?: ThisTypedComponentOptionsWithRecordProps<V, Data, Methods, Computed, Props>
):  ExtendedVue<V, Data, Methods, Computed, Props> {
    return Vue.extend(options)
}

🙁 Actual behavior

4.6.2:

$ npx tsc src/file.ts
src/file.ts:13:5 - error TS2322: Type 'ExtendedVue<Vue, Data, Methods, Computed, Props>' is not assignable to type 'ExtendedVue<V, Data, Methods, Computed, Props>'.
  Type 'Data & Methods & Computed & Props & Vue' is not assignable to type 'Data & Methods & Computed & Props & V & Vue'.
    Type 'Data & Methods & Computed & Props & Vue' is not assignable to type 'V'.
      'V' could be instantiated with an arbitrary type which could be unrelated to 'Data & Methods & Computed & Props & Vue'.

13     return Vue.extend(options)
       ~~~~~~~~~~~~~~~~~~~~~~~~~~

I tried to change to the following, but the result is the same:

    V extends Vue & Data & Methods & Computed & Props,

🙂 Expected behavior

4.5.5:

$ npx tsc src/file.ts
(no error)

Activity

  1. RyanCavanaugh commented on Mar 5, 2022

    @RyanCavanaugh
    Member

    Bisected to #47341

  2. RyanCavanaugh commented on Mar 5, 2022

    @RyanCavanaugh
    Member

    Seems like a duplicate of #47371; the PR is associated with a documented breaking change

  3. provegard commented on Mar 5, 2022

    @provegard
    Author

    Ok, I see! Is there anything I can do in the definition of defineComponent, or is the Vue type definition at fault?

  4. typescript-bot commented on Mar 7, 2022

    @typescript-bot
    Contributor

    This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

  5. locked as resolved and limited conversation to collaborators on Oct 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions