Skip to content

Allow generics for Data, Methods, Computed and Props in defineComponent to ease migration from Vue2 #7433

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

Open
mediafreakch opened this issue Dec 30, 2022 · 0 comments
Labels

Comments

@mediafreakch
Copy link

mediafreakch commented Dec 30, 2022

What problem does this feature solve?

We have a largish code base in Vue2 and are looking into upgrading it to Vue3. We already use Typescript, but without class components. The way we write components in Vue2 is this:

import Vue from 'vue'

interface Data {
  isActive: boolean
}

interface Methods {
  updateRemote(payload: ApiPayload, options: ApiOptions): void
}

interface Computed {
  selectItems: <string, number>[]
}

interface Props {
  mapType: "osm" | "swiss" | "france"
}

export default Vue.extend<Data, Methods, Computed, Props>({
  name: 'MyComponent',
  props: ["mapType"], // or object
  data() {
     isActive: false
  },
  methods: {
    updateRemote(payload, options) {}
  },
  computed: {
    selectItems() { }
  }
})

This has worked well for us so far. In Vue3, extend has been removed and the way to go is to use defineComponent. However, this function doesn't seem to expose the same generics as Vue.extend did. This makes migration from Vue2 quite costly.

Do you see a way to retrofit defineComponent with an overload that accepts Data, Methods, Computed and Props as Typescript generics?

Partly related to #3102

What does the proposed API look like?

const myComponent = defineComponent<Data, Methods, Computed, Props>({
  ...
})
@mediafreakch mediafreakch added the ✨ feature request New feature or request label Dec 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants