Skip to content

Commit

Permalink
Remove any properties from the base HTMLFormElement when computin…
Browse files Browse the repository at this point in the history
…g JSX props
  • Loading branch information
edoardocavazza committed Jul 4, 2024
1 parent b50e1ff commit 688da65
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/metal-snakes-carry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@chialab/dna": patch
---

Remove `any` properties from the base `HTMLFormElement` when computing JSX props.
2 changes: 1 addition & 1 deletion src/Component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ export const extend = <T extends HTMLElement, C extends { new (...args: any[]):
cancelable?: boolean,
composed?: boolean
) {
return dispatchEvent(this, event as string, detail, bubbles, cancelable, composed);
return dispatchEvent(this, event, detail, bubbles, cancelable, composed);
}

/**
Expand Down
21 changes: 17 additions & 4 deletions src/JSX.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ const V_SYM: unique symbol = Symbol();
*/
type IfMethod<T, K extends keyof T, A, B> = T[K] extends Function ? A : B;

/**
* Check if a property is any.
*/
type IfAny<T, K extends keyof T, A, B> = 0 extends 1 & T[K] ? A : B;

/**
* Exclude component mixin properties.
*/
Expand Down Expand Up @@ -47,13 +52,21 @@ type ReservedKeys =
| Exclude<keyof Element, 'id' | 'className'>
| keyof ElementCSSInlineStyle;

/**
* Extract known keys of an Element class.
*/
type KnownKeys<T> = keyof {
[K in keyof T as K extends string ? IfAny<T, K, never, K> : never]: unknown;
};

/**
* Pick defined properties of a component.
*/
export type Props<T extends HTML.Element> = ElementAttributes<T> & {
[K in keyof T as K extends ReservedKeys
? never
: IfMethod<T, K, never, K extends keyof BaseClass<T> ? never : K>]?: T[K];
export type Props<
T extends HTML.Element,
InvalidKeys = ReservedKeys | KnownKeys<BaseClass<T>>,
> = ElementAttributes<T> & {
[K in keyof T as K extends InvalidKeys ? never : IfMethod<T, K, never, K>]?: T[K];
};

/**
Expand Down

0 comments on commit 688da65

Please sign in to comment.