You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
git clone git@github.com:justin-schroeder/vue-3.3-prop-unions.git
cd vue-3.3-prop-unions.git
pnpm install
pnpm build
What is expected?
There are 2 ideas to highlight here:
TypeScript
The example defines a component using the new function syntax for defineComponent with a discriminated union as the prop type. Each union type has 1 prop the other type does not have (bar vs foo). The runtime props include bothbar and foo to ensure they are both accepted at runtime.
I would expect this to work properly since the runtime props are inclusive of all unions, there is no overload that allows for the runtime props to differ from the union props even if the runtime props are only defining additional props. Volar is actually ok with this typing, but Vue itself does not have a matching component overload. For example:
Adding an additional overload for defineComponent seems like it may sufficiently address this.
Runtime prop proposal
Alternatively, it would be ideal to allow for runtime props to be determined at runtime. This seems like it would be primary beneficial to library authors, so perhaps no SFC compatibility is necessary. One option:
Vue version
3.3.4
Link to minimal reproduction
https://github.com/justin-schroeder/vue-3.3-prop-unions
Steps to reproduce
Clone the repository and install:
git clone git@github.com:justin-schroeder/vue-3.3-prop-unions.git cd vue-3.3-prop-unions.git pnpm install pnpm build
What is expected?
There are 2 ideas to highlight here:
TypeScript
The example defines a component using the new function syntax for
defineComponent
with a discriminated union as the prop type. Each union type has 1 prop the other type does not have (bar
vsfoo
). The runtime props include bothbar
andfoo
to ensure they are both accepted at runtime.I would expect this to work properly since the runtime props are inclusive of all unions, there is no overload that allows for the runtime props to differ from the union props even if the runtime props are only defining additional props. Volar is actually ok with this typing, but Vue itself does not have a matching component overload. For example:
Adding an additional overload for
defineComponent
seems like it may sufficiently address this.Runtime prop proposal
Alternatively, it would be ideal to allow for runtime props to be determined at runtime. This seems like it would be primary beneficial to library authors, so perhaps no SFC compatibility is necessary. One option:
What is actually happening?
System Info
Any additional comments?
No response
The text was updated successfully, but these errors were encountered: