-
-
Notifications
You must be signed in to change notification settings - Fork 390
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
defineComponent
cross-property generics usage is broadened on usage
#3782
Labels
Comments
Duplicate of #3745? |
A hack I’ve used to fix a similar issue: Define an explicit return type, including Volar’s special In your case, import { type VNode, defineComponent } from "vue";
export const Test2 = defineComponent(
<TStr extends "one" | "two", TNum extends TStr extends "one" ? 1 : 2>(props: {
str: TStr;
num: TNum;
numFn: (num: TNum) => TNum;
}) => {
return () => props.str;
}
) as <TStr extends "one" | "two", TNum extends TStr extends "one" ? 1 : 2>(props: {
str: TStr;
num: TNum;
numFn: (num: TNum) => TNum;
}) => VNode & {
__ctx?: {
props: {
str: TStr;
num: TNum;
numFn: (num: TNum) => TNum;
};
};
}; By changing |
I added a test case and found that this issue should have been solved in Vue 3.4, if you are using <= 3.3 please make sure to upgrade. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have a
.vue
file that accepts generic types like so:And when using it in
App.vue
, it works just as expected to infer the values ofnumFn
:However, when using
defineComponent
and generics inside like so:The type inferencing no longer works:
Link to Reproduction
https://github.com/crutchcorn/vue-define-component-ts-broadening-bug
https://stackblitz.com/github/crutchcorn/vue-define-component-ts-broadening-bug
The text was updated successfully, but these errors were encountered: