-
Notifications
You must be signed in to change notification settings - Fork 11
chore(): 修复如果brick设置了原生属性报错问题 #4854
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
base: v3
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,19 +25,26 @@ type MapEvents<E, M> = { | |
| [key in keyof M]?: M[key] extends keyof E ? (e: E[M[key]]) => void : never; | ||
| }; | ||
|
|
||
| export function wrapLocalBrick<T extends HTMLElement, P, E, M extends object>( | ||
| export function wrapLocalBrick< | ||
| T extends Partial<HTMLElement>, | ||
| P, | ||
| E, | ||
| M extends object, | ||
| >( | ||
| brick: Constructable<T> | string, | ||
| eventsMapping: M | ||
| ): WrappedBrickWithEventsMap<T, P, E, M>; | ||
|
|
||
| export function wrapLocalBrick<T extends HTMLElement, P>( | ||
| export function wrapLocalBrick<T extends Partial<HTMLElement>, P>( | ||
| brick: Constructable<T> | string | ||
| ): WrappedBrick<T, P>; | ||
|
Comment on lines
+38
to
40
|
||
|
|
||
| export function wrapLocalBrick<T extends HTMLElement, P, _E, M extends object>( | ||
| brick: Constructable<T> | string, | ||
| eventsMapping?: M | ||
| ) { | ||
| export function wrapLocalBrick< | ||
| T extends Partial<HTMLElement>, | ||
| P, | ||
| _E, | ||
| M extends object, | ||
| >(brick: Constructable<T> | string, eventsMapping?: M) { | ||
| // istanbul ignore next | ||
| if (process.env.NODE_ENV === "development") { | ||
| if (typeof brick === "string" && !customElements.get(brick)) { | ||
|
|
@@ -62,19 +69,23 @@ export function wrapLocalBrick<T extends HTMLElement, P, _E, M extends object>( | |
| ); | ||
| } | ||
|
|
||
| export function wrapBrick<T extends HTMLElement, P, E, M extends object>( | ||
| BrickName: string, | ||
| eventsMapping: M | ||
| ): WrappedBrickWithEventsMap<T, P, E, M>; | ||
| export function wrapBrick< | ||
| T extends Partial<HTMLElement>, | ||
| P, | ||
| E, | ||
| M extends object, | ||
| >(BrickName: string, eventsMapping: M): WrappedBrickWithEventsMap<T, P, E, M>; | ||
|
Comment on lines
+72
to
+77
|
||
|
|
||
| export function wrapBrick<T extends HTMLElement, P>( | ||
| export function wrapBrick<T extends Partial<HTMLElement>, P>( | ||
| BrickName: string | ||
| ): WrappedBrick<T, P>; | ||
|
|
||
| export function wrapBrick<T extends HTMLElement, P, _E, M extends object>( | ||
| BrickName: string, | ||
| eventsMapping?: M | ||
| ) { | ||
| export function wrapBrick< | ||
| T extends Partial<HTMLElement>, | ||
| P, | ||
| _E, | ||
| M extends object, | ||
| >(BrickName: string, eventsMapping?: M) { | ||
| return forwardRef<T, HTMLAttributes<T> & PropsWithChildren<P>>( | ||
| function BrickReactWrapper({ children, ...props }, ref: Ref<T>) { | ||
| const properties = getMappedProperties( | ||
|
|
||
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.
The new generic constraint
T extends Partial<HTMLElement>makes almost any object type assignable (since allHTMLElementmembers are optional), which meansref/event handler generics can now be something that is not actually a DOM element. If the goal is only to relax structural compatibility while still guaranteeing a real element instance, consider constrainingTto a DOM base type (e.g.Element/HTMLElement) and introducing a separate type parameter for any “looser” view of the instance, rather than weakening the element constraint toPartial<HTMLElement>.