Open DawidKopys opened 1 year ago
Generics cannot be used in the way you are doing; in your code, the T is treated as a concrete type.
type Props<T> = {
color?: T;
}
withDefaults(
defineProps<Props<Color>>(),
{
color: Color.RED,
}
);
What do you mean? I can use generics this way according to vue docs here.
Vue version
3.3.4
Link to minimal reproduction
https://stackblitz.com/edit/vitejs-vite-ozff8b?file=src%2Fcomponents%2FGenericComponent.vue
Steps to reproduce
Run
npx vue-tsc --noEmit
What is expected?
No TS errors
What is actually happening?
TypeScript error is shown:
System Info
Any additional comments?
Component
GenericComponent.vue
has one prop -color
- which is defined using generic typeT
with constraint... extends Color
.Then, this
Color
enum is used to set the default value of thecolor
prop.