Subscribe on changes!

Using `defineComponent` in `<script>` with `<script setup>` takes type error

avatar
Nov 10th 2021

For components which using both <script> and <script setup>, and using defineComponent in <script>, when I try to generate declaration files from the compilation results, type errors are issued.

Version

3.2.21

Reproduction link

sfc.vuejs.org/

Steps to reproduce

Use vscode to open any project which contains vue and typescript dependencies (can use vite-create to create a vue-ts project), then copy sfc js compilation result into a new ts file.

This is to simulate type diagnostic when generate declaration files.

What is expected?

No type error occurred.

What is actually happening?

image

defineComponent returned type is not assignable to parameter type.

In official example is export a native object, it seems to be the best practice.

image

If so, there will be some warnings when the usage is not recommended?

Thank you.

avatar
Nov 11th 2021

You need to write on top of

avatar
Nov 11th 2021

@xiuxiuyifan This may lead to the same result.