core icon indicating copy to clipboard operation
core copied to clipboard

[@vue/compiler-sfc] Unresolvable type: TSConditionalType

Open Boke-Space opened this issue 1 year ago • 4 comments

Vue version

3.4.27

Link to minimal reproduction

https://stackblitz.com/edit/vitejs-vite-wennky?file=src%2FApp.vue,tsconfig.json,src%2Fmain.ts,src%2Fcomponents%2FHelloWorld.vue,src%2Fcomponents%2Ftype.ts,src%2Fcomponents%2FTable.vue&terminal=dev

Steps to reproduce

屏幕截图 2024-07-16 151928

组件Helloworld引入类型TableEmits发生错误 屏幕截图 2024-07-16 145235 组件Test引入类型TableEmits成功运行 屏幕截图 2024-07-16 150222

What is expected?

组件HelloWorld传入ElTable得到事件的联合类型

屏幕截图 2024-07-16 150222

What is actually happening?

屏幕截图 2024-07-16 145235

[plugin:vite:vue] [@vue/compiler-sfc] Unresolvable type: TSConditionalType

/home/projects/vitejs-vite-wennky/node_modules/.pnpm/[email protected]/node_modules/vue-component-type-helpers/index.d.ts 10 | emit: any; 11 | }, ...args: any) => any ? NonNullable<S> : {}; 12 | export type ComponentEmit<T> = T extends new (...angs: any) => { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13 | $emit: infer E; | ^^^^^^^^^^^^^^^^^^^ 14 | } ? NonNullable<E> : {}; | ^^^^^^^^^^^^^^^^^^^^^^^

System Info

No response

Any additional comments?

No response

Boke-Space avatar Jul 16 '24 07:07 Boke-Space

This limitation has been resolved in 3.3. The latest version of Vue supports referencing imported and a limited set of complex types in the type parameter position. However, because the type to runtime conversion is still AST-based, some complex types that require actual type analysis, e.g. conditional types, are not supported. You can use conditional types for the type of a single prop, but not the entire props object.

https://vuejs.org/api/sfc-script-setup.html#type-only-props-emit-declarations

Try https://github.com/so1ve/vue.ts/tree/main/packages/complex-types

edison1105 avatar Jul 18 '24 12:07 edison1105

Hi! I have similar issue with class-variance-authority library which is very painful(( Screenshot 2024-08-23 at 12 26 40

kyselberg avatar Aug 23 '24 09:08 kyselberg

Hi! I have similar issue with class-variance-authority library which is very painful(( Screenshot 2024-08-23 at 12 26 40

Did you perhaps find a solution to this? 🥲

dsijakovski98 avatar Sep 28 '24 11:09 dsijakovski98

Hi! I have similar issue with class-variance-authority library which is very painful(( Screenshot 2024-08-23 at 12 26 40

Did you perhaps find a solution to this? 🥲

As sated in Edison's response:

You can use conditional types for the type of a single prop, but not the entire props object.

So, as long as the conditional type is not used on the root object everything is working fine. I'm doing the following:

<script setup lang="ts">
import { cva, type VariantProps } from "class-variance-authority"; 
const buttonVariants = cva("…", {
  variants: {
    display: { a: "…", b: "…" },
  },
});

type ButtonVariantProps = {
  variants: VariantProps<typeof buttonVariants>;
}

defineProps<ButtonVariantProps>()
</script>

<template>
  <section :class="buttonVariants(variants)">
    ...
  </section>
</template>

felixdenoix avatar Nov 20 '25 16:11 felixdenoix