-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
feat: Support for generic props component #3682
base: main
Are you sure you want to change the base?
Conversation
PP | ||
> = | ||
// If props is a class we should ifnore all the process | ||
(PropsOrPropOptions extends { prototype: ComponentOptionClass } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the most important part of this PR, this pretty much bypasses our ComponentPublicInstanceConstructor
to prevent the Props
type to not be modified
PP | ||
> = | ||
// If props is a class we should ifnore all the process | ||
(PropsOrPropOptions extends { prototype: ComponentPropsOverride } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo :)
Hey @pikax , you have done a great job 👍, it looks simpler than expected, do we need to add some dts test cases for mixins/extends? |
Not sure, because it will ignore all the declare function expectType<T>(a: T): void;
type OnChange<ValueType, Clearable> = Clearable extends true
? (value: ValueType | null) => void
: (value: ValueType) => void
interface GenericProp<Clearable, ValueType> {
clearable?: Clearable
value?: ValueType
onChange?: OnChange<ValueType, Clearable>
}
declare function S<
Clearable extends boolean,
ValueType extends string | number | null | undefined
>(): {
$props: GenericProp<Clearable, ValueType>
}
S().$props // $props is not `GenericProp<Clearable, ValueType>`
class C<
Clearable extends boolean,
ValueType extends string | number | null | undefined
> {
$props = {} as GenericProp<Clearable, ValueType>
}
new C().$props // $props is not `GenericProp<Clearable, ValueType>`
// but `C` has the correct type
// This would also work
type VueProps<T extends new () => { $props: any }> = T
declare const Comp: VueProps<{
new <
Clearable extends boolean,
ValueType extends string | number | null | undefined
>(): { $props: GenericProp<Clearable, ValueType> }
}> The templated constructor intact to keep the correct I would say this is an advanced usage, with the current implementation it won't support Public API typing would also been lost, since the constructor will only return |
I agree with this point |
Must we create a new class for props definition? |
fix #3102
Allow generic components through a class component declaration.
Class maintain the correct type, if we use function or even the current DefineComponent the finer type will be lost.
This overload allows for the users to override the types to a finer grain
Open for better solutions
example