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
Define a prop named icon as a union type of at least 315 literal values and a non-primitive type (e.g. object, array, class,...)
Use it via props.icon
TypeScript raises an error with id TS2590: Expression produces a union type that is too complex to represent.
vue-tsc --noEmit also raises the same error (can try it in the Stackblitz Terminal)
Just delete 1 literal string from the union type and the error is gone immediately
What is expected?
TypeScript shouldn't raise the error as the number of union literal strings is not that large (only 315). In fact, I'm still able to use the union type in other types seamlessly without any issues.
What is actually happening?
Not sure what is happening but I think the root cause is due to some adjustments on the DefineProps type of @vue/runtime-core starting from version 3.3.9.
I tried the same setup on Vue 3.3.8 and no error was raised.
I think the use-case of defining a prop like this is quite valid because usually, I want the callers to benefit from literal value type checking and auto-completion so they only need to specify a single value whilst giving them the ability to add more relevant properties. It's more "composition over inheritance" I would say.
The text was updated successfully, but these errors were encountered:
Vue version
3.4.21
Link to minimal reproduction
https://stackblitz.com/edit/vitejs-vite-th8k9t?file=src%2FApp.vue
Steps to reproduce
icon
as a union type of at least 315 literal values and a non-primitive type (e.g. object, array, class,...)props.icon
TS2590: Expression produces a union type that is too complex to represent.
vue-tsc --noEmit
also raises the same error (can try it in the Stackblitz Terminal)What is expected?
TypeScript shouldn't raise the error as the number of union literal strings is not that large (only 315). In fact, I'm still able to use the union type in other types seamlessly without any issues.
What is actually happening?
Not sure what is happening but I think the root cause is due to some adjustments on the
DefineProps
type of@vue/runtime-core
starting from version3.3.9
.I tried the same setup on Vue
3.3.8
and no error was raised.System Info
Any additional comments?
I think the use-case of defining a prop like this is quite valid because usually, I want the callers to benefit from literal value type checking and auto-completion so they only need to specify a single value whilst giving them the ability to add more relevant properties. It's more "composition over inheritance" I would say.
The text was updated successfully, but these errors were encountered: