fix: resolve TypeScript interface conflicts between component methods and HTMLElement#6282
Merged
christian-bromann merged 2 commits intomainfrom Jun 11, 2025
Merged
Conversation
… and HTMLElement Fixes #4467 When Stencil components have @method() decorators on methods with names that match HTMLElement methods (like 'focus', 'blur', 'click'), TypeScript fails to compile due to incompatible method signatures between the component interface and HTMLStencilElement. This commit implements conflict detection and resolution by: - Adding comprehensive HTML_ELEMENT_METHODS constant covering HTMLElement, Element, Node, and EventTarget method names - Detecting method name conflicts during type generation - Using TypeScript's Omit utility type to exclude conflicting methods from component interface and re-declare them with correct signatures - Preserving JSDoc documentation for conflicting methods - Maintaining backward compatibility for components without conflicts The solution generates interfaces like: `interface HTMLMyButtonElement extends Omit<Components.MyButton, "focus">, HTMLStencilElement` with explicit method overrides when conflicts are detected. Includes comprehensive tests covering single conflicts, multiple conflicts, mixed scenarios, and JSDoc preservation.
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What is the current behavior?
GitHub Issue Number: #4467
When Stencil components have
@Method()decorators on methods with names that match HTMLElement methods (such asfocus,blur,click, etc.), TypeScript compilation fails with interface conflict errors.Example of failing code:
Current error:
This occurs because:
focus(): Promise<void>focus(options?: FocusOptions): voidWhat is the new behavior?
The TypeScript type generation now automatically detects and resolves method name conflicts between Stencil component methods and native HTMLElement methods.
Solution approach:
Omitutility type to exclude conflicting methods and re-declare them with correct signaturesGenerated interface examples:
Without conflicts (unchanged):
With conflicts (new):
Multiple conflicts:
Comprehensive method coverage:
focus,blur,click,attachInternals, etc.getAttribute,setAttribute,querySelector,animate, etc.appendChild,removeChild,cloneNode,contains, etc.addEventListener,removeEventListener,dispatchEventDocumentation
N/A - This is an internal type generation improvement that doesn't require user-facing documentation changes.
Does this introduce a breaking change?
This change is fully backward compatible. Existing components without method conflicts will generate identical interfaces as before. Components with conflicts will now compile successfully instead of failing.
Testing
Comprehensive test suite added (
src/compiler/types/tests/generate-component-types.spec.ts):focusmethod conflict resolutionfocus,blur, andclickconflicts simultaneouslyManual testing:
.d.tsfiles contain correct interface definitionsOther information
Key technical details:
HTML_ELEMENT_METHODSconstant with 80+ method names covering the complete DOM API surfaceOmit<Components.ComponentName, "methodName">pattern for clean type exclusionFiles modified:
src/compiler/types/generate-component-types.ts- Main implementationsrc/compiler/types/constants.ts- HTML method names constantsrc/compiler/types/tests/generate-component-types.spec.ts- Comprehensive testsThis fix enables developers to use any method names in their Stencil components without worrying about conflicts with native DOM APIs, while maintaining full type safety.