language-tools icon indicating copy to clipboard operation
language-tools copied to clipboard

Typescript error when defineComponent is not used on a mixin

Open prof-schnitzel opened this issue 2 years ago • 4 comments

I work on vuejs apps that are partly migrated to typescript. Since version 1.8.12 we get new type errors that haven't been there before. Take a look at this code.

App.vue

<template>
    <div>
      <my-component />
    </div>
</template>

<script lang="ts">
import { defineComponent } from 'vue'
import MyComponent from './components/MyComponent.vue'
import MyMixin from './mixins/MyMixin'

export default defineComponent({
  name: 'MyApp',
  mixins: [MyMixin],
  components: {
    MyComponent,
  },
})
</script>

MyMixin.js

export default {
  methods: {
    foobar() {
      console.log("foobar");
    },
  },
};

This gives me the error: src/App.vue:3:8 - error TS2345: Argument of type '{}' is not assignable to parameter of type 'never'. I see these errors all over my projects because we use partly typescript, partly javascript. When I insert defineComponent in MyMixin.js, everything works fine. But is this breaking change really intended? Until version 1.8.11 everything worked fine.

You can use this playground link to see the typescript error by yourself: https://codesandbox.io/p/sandbox/blue-wildflower-42ltq6

prof-schnitzel avatar Sep 29 '23 10:09 prof-schnitzel

This seemed to be a bug in vue core.

so1ve avatar Oct 05 '23 15:10 so1ve

Likely same issue as #3374, which is also resolved by downgrading to v1.8.11.

IGx89 avatar Oct 13 '23 19:10 IGx89

any news?

juztinlazaro avatar Mar 04 '24 13:03 juztinlazaro

+1

Klapeks avatar Jun 06 '24 14:06 Klapeks

If this problem still happens in the latest version, feel free to open a new issue.

KazariEX avatar Nov 03 '24 06:11 KazariEX