Proper typing with Vue2 + vue-property-decorator + @vue/composition-api (TypeScript)

312 Views Asked by At

Suppose a Vue component is written like

import { Vue, Component } from "vue-property-decorator";
// ...

@Component({
   setup () {
      const { something } = useComposable();
      return { something }
   }
})
export default class DummyComponent extends Vue {
   doSomething(command: string) {
       this.something // issue
   }
}

Two issues here:

  1. TS2339: Property 'something' does not exist on type 'DummyComponent'. and
  2. this.something is not typed.

Adding an index signature ([x: string]: any;) seems like a bad workaround to satisfy the linter / tsc and setting the return type of the setup method does not solve the issue #1. Is there the right way to do it or am I mixing stuff that's not supposed to be mixed. I'm sure the awesome Vue devs thought of that?

What's the proper way to satisfy tsc?

0

There are 0 best solutions below