Skip to content

Vue.extend return type error TS2322 with 4.6.2 #48089

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
provegard opened this issue Mar 2, 2022 · 4 comments
Closed

Vue.extend return type error TS2322 with 4.6.2 #48089

provegard opened this issue Mar 2, 2022 · 4 comments
Labels
Duplicate An existing issue was already created

Comments

@provegard
Copy link

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)
@RyanCavanaugh
Copy link
Member

Bisected to #47341

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Mar 5, 2022
@RyanCavanaugh
Copy link
Member

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

@provegard
Copy link
Author

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

@typescript-bot
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants