Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect type inferring with generic components and withDefaults #8325

Closed
grindpride opened this issue May 15, 2023 · 4 comments · Fixed by #8335
Closed

Incorrect type inferring with generic components and withDefaults #8325

grindpride opened this issue May 15, 2023 · 4 comments · Fixed by #8335

Comments

@grindpride
Copy link

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

  1. Open a new Terminal after successful setup of dependencies
  2. type and run npm run typecheck into the terminal
  3. 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

@xiaoxiangmoe
Copy link
Contributor

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.

@xiaoxiangmoe
Copy link
Contributor

duplicated to #8310

@grindpride
Copy link
Author

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; }>>'.

@xiaoxiangmoe
Copy link
Contributor

@grindpride This is another error. duplicated to #8331

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants