Subscribe on changes!

`defineProps` is unable to parse the types generated from `ExtractPropTypes`

avatar
Dec 7th 2023

Vue version

3.3.10

Link to minimal reproduction

https://play.vuejs.org/#eNp9Uk1rwzAM/SuaL+2gaxi9hbSwjcK2w1bWwi6+hERJ0zm2sZWuI+S/T3HoB2MUArHee5KfZLXiwdrpvkERi8RnrrIEHqmxoFJdzqUgL8VC6qq2xhG04LCYLA/k0oxWztjNj0UPHRTO1DDiOiOpM6M9AaEPCg9zaKUGSOPwAyDOiWFNrtJlj3RS8yd1j8PmIu3vPUmvMMW5NBvLsag0hig55S7Gt33BwUjtS67FvsejZ1TKwKdxKr8ZsSSJhpa5DgeEtVUpIUcAyfZ+0bYhueuSiKOAVto2BPu72uSoeDzMSwERk0l0kS8mPDi+vqjK6c4bzdMNzUuRmdpWCt27pYrtSREP0+m5lN19vwaMXIOTI55tMfv6B9/5Q49JsXLo0e1RihNHqSuRBnq5fsMDn08ku28Uq6+QH+iNanqPg+yx0TnbvtAFty9hL/ghN55fC7U/NtUbDY8b9FLwajxdaf1sdzadHZdCdL8mAeOA

Steps to reproduce

see the reproduction

What is expected?

I hope that defineProps can parse the types generated from ExtractPropTypes.

What is actually happening?

Currently, attempting to parse with defineProps from ExtractPropTypes results in errors. Any reference for a workaround or solution would be appreciated.

System Info

No response

Any additional comments?

No response

avatar
Dec 9th 2023
avatar
Dec 9th 2023

List of TypeScript errors in Vue (SFC) files I faced

  • [@vue/compiler-sfc] Unresolvable type: TSConditionalType
  • [@vue/compiler-sfc] Unresolvable type: TSTypeQuery
  • [@vue/compiler-sfc] Failed to resolve extends base type. If this previously worked in 3.2, you can instruct the compiler to ignore this extend by adding /* @vue-ignore */ before it

@so1ve Can we expect @vue.ts/complex-types in the Vue Core :pray:?

I wonder how the Svelte compiler supports complex types? Class Variance Authority Svelte example


https://github.com/vuejs/rfcs/discussions/549 https://github.com/vuejs/rfcs/discussions/547


https://github.com/vuejs/core/pull/9556

If we don't get complex types support for SFC some of the type helpers will be pointless, But it's working in .ts or .tsx right? but Vue Compiler can optimize .vue files

avatar
Dec 10th 2023

@sadeghbarati Svelte doesn't "resolve" types to runtime props actually - these type definitions are only used for IDE usage, and they don't affect runtime behavior. But vue needs them to cast types.

avatar
Dec 11th 2023

@aibayanyu20 do you mind providing an use case for this?

The only use case I see this is when retrieving props from an imported component, if that's the use case I believe is better accessing the component props directly instead of generating through types

<script setup>
import Comp from './Comp.vue'


// this will be supported on https://github.com/vuejs/core/pull/9556
defineProps(Comp.props)
</script>

Since of the limitation when using defineProps with type based, I would recommend object based instead.

avatar
Dec 11th 2023

like this online demo ?

avatar
Dec 11th 2023

like this online demo ?

No, not a reproduction, but actual use case, why do you take that approach instead of another approach

avatar
Dec 11th 2023
image Maybe I explained here why this is used
avatar
Dec 11th 2023

This does seem to be a problem, regardless of the usage and writing method, I still hope this situation can be dealt with, thanks

avatar
Mar 1st 2024
image Maybe I explained here why this is used

It's the exact use case for Tailwind Variants, where you get variants as typeof from VariantProps util, Vue compiler resolve as TSConditionalType bug.