-
Notifications
You must be signed in to change notification settings - Fork 40
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
Generics not working for component definitions when upgrading to version 3+ #87
Comments
This code works with [email protected] (with [email protected] or 4.3.5) import { Component, Prop } from "vue-property-decorator";
import * as vuetsx from "vue-tsx-support";
interface ListProp<T> {
items: T[];
}
@Component
class AList<T> extends vuetsx.Component<ListProp<T>> {
@Prop()
items!: T[];
}
const items: number[] = [1, 2, 3];
<AList items={items} />; BTW, you can obtain typed component like below. const ANumberList = AList as new () => AList<number>;
<ANumberList items={[1, 2, 3]} />; |
Thank you for the answer - I'll see if I can followup with a minimal reproduction example. |
Hello @wonderful-panda and @LolliDepp As you can see,
Here is the code to reproduce (based on @wonderful-panda, but I think you did not check correctly the type, happens :)) : /* eslint-disable max-classes-per-file */
import { Component, Prop } from 'vue-property-decorator';
import * as vuetsx from 'vue-tsx-support';
interface ListProp<T> {
items: T[];
}
@Component
class AList<T extends number | string> extends vuetsx.Component<
ListProp<T>,
{}
> {
@Prop()
items!: T[];
}
@Component
class Test extends vuetsx.Component<{}> {
render() {
const items = [1, 2, 3, '2'];
// enable this to check TypeScript error
// const items = [1, 2, 3, '2', new Date()];
return <AList<number> items={items} />;
}
}
function test<T extends string | number>(items: T[]) {
return false;
}
test<number>([1, 2, 'sd']); Please do not hesitate to ask if you need more details. |
If I upgrade to version 3.2.0 from 2.3.3, generics stop working in my components
With
2.3.3
I can use AList in other .tsx files and provide any kind of array foritems
and it will worksWith
3.2.0
all my other components using AList are giving me error becauseTType
of AList is inferred to be of typeunknown
insteadThe text was updated successfully, but these errors were encountered: