Incorrect type inferring with generic components and withDefaults
Vue version
3.3.2
Link to minimal reproduction
https://stackblitz.com/edit/vitejs-vite-nwkbil?file=src/components/ListGeneric.vue
Steps to reproduce
Steps to reproduce
- Open a new Terminal after successful setup of dependencies
- type and run
npm run typecheck
into the terminal - See an error in
ListGeneric.vue
file
What is expected?
There is no error occurred
What is actually happening?
TS error
TS2345: Argument of type '{ sameModel: string; }' is not assignable to parameter of type 'InferDefaults<DefineProps<{ modelValue: T; sameModel?: T | undefined; }>>'.
System Info
No response
Any additional comments?
No response
This is work as intended
For example:
function someFunction<T extends string>(
sameModel: T = 'sameModel default'
) {
}
Type 'string' is not assignable to type 'T'.
'string' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'string'.ts(2322)
So withDefaults should throw a error for this, also.
duplicated to https://github.com/vuejs/core/issues/8310
if i change define props to
withDefaults(
defineProps<{
modelValue: T;
sameModel?: string;
}>(),
{
sameModel: 'sameModel default',
}
);
its stil throws error
TS2345: Argument of type '{ sameModel: string; }' is not assignable to parameter of type 'InferDefaults<DefineProps<{ modelValue: T; sameModel?: string | undefined; }>>'.
@grindpride This is another error. duplicated to https://github.com/vuejs/core/issues/8331