vuejs / core

🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
https://vuejs.org/
MIT License
46.71k stars 8.19k forks source link

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

Open aibayanyu20 opened 9 months ago

aibayanyu20 commented 9 months ago

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

so1ve commented 9 months ago

Try @vue.ts/complex-types

sadeghbarati commented 9 months ago

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

@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

so1ve commented 9 months ago

@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.

pikax commented 9 months ago

@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.

aibayanyu20 commented 9 months ago

like this online demo ?

pikax commented 9 months ago

like this online demo ?

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

aibayanyu20 commented 9 months ago
image

Maybe I explained here why this is used

aibayanyu20 commented 9 months ago

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

mrcego commented 6 months ago
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.