Skip to content

Vue.extend return type error TS2322 with 4.6.2 #48089

@provegard

Description

@provegard

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions