-
Notifications
You must be signed in to change notification settings - Fork 1k
Closed
Description
Proposal - Add Generic Element Type Support to Hook Interface
Summary
The current Hook interface in Phoenix LiveView's TypeScript definitions always types the el property as HTMLElement, which prevents developers from leveraging TypeScript's type system when working with specific HTML element types in hooks.
Use Cases
Many LiveView hooks are designed to work with specific types of HTML elements and need access to element-specific properties and methods:
Form Hooks
const FormValidationHook = {
mounted() {
// Need access to form-specific properties like .elements, .method, .action
// Currently requires casting: (this.el as HTMLFormElement).elements
this.el.addEventListener('submit', this.validateForm);
}
};Current Limitation
The HookInterface is defined with a generic HTMLElement type:
export interface HookInterface {
el: HTMLElement; // Always HTMLElement - no element-specific typing
// ...
}Desired Outcome
Hooks should be able to specify what type of HTML element they expect to work with.
This enhancement would significantly improve the TypeScript developer experience. I will be happy to make this change, just wanna make sure that you guys are fine with it.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels