Skip to content

bug: Breaking Type Incompatibility: HTMLStencilElement.autocorrect ('on' | 'off') vs HTMLElement.autocorrect (boolean) #6425

@MathisPct

Description

@MathisPct

Prerequisites

Stencil Version

4.38.1

Current Behavior

When using Stencil 4.38.1 release that edit HTMLStencilElement (fb16240) to redefine the autocorrect property (autocorrect: 'on' | 'off'), any Stencil-generated custom element type (e.g. HTMLMyComponentElement) becomes structurally incompatible with the built-in HTMLElement type provided by the active TypeScript DOM lib (where HTMLElement still has autocorrect: boolean). You Omit autocomplete: boolean and replace with autocomplete: 'on' | 'off' which is not present for now in the current version of the type dom.generated.d.ts (https://github.com/microsoft/TypeScript/blob/main/src/lib/dom.generated.d.ts#L14108) in Typescript

import { Component, Host, Prop, h, Element } from '@stencil/core';
import { format } from '../../utils/utils';

@Component({
  tag: 'my-component',
  styleUrl: 'my-component.css',
  shadow: true,
})
export class MyComponent {
  @Element() el: HTMLMyComponentElement;

  componentDidLoad() {
    // Type error here
    this.test(this.el);
  }

  test(element: HTMLElement) {
    console.log(element);
  }

  render() {
    return (
      <Host>
          blabla
      </Host>
    );
  }
}

When you build that, it causes the following TS error

[ ERROR ]  TypeScript: src/components/my-component/my-component.tsx:38:15
           Argument of type 'HTMLMyComponentElement' is not assignable to parameter of type 'HTMLElement'.Types of
           property 'autocorrect' are incompatible.Type 'string' is not assignable to type 'boolean'.Type 'string' is
           not assignable to type 'boolean'.

     L38:      this.test(this.el);
     L39:    }

[23:41.8]  build failed in 4.20 s

Expected Behavior

No TS build error

System Info

System: node 22.14.0
    Platform: windows (10.0.22631)
   CPU Model: Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz (12 cpus)
    Compiler: C:\Users\Stenciljs\test-bug-component-did-load-child-query-selector\node_modules\@stencil\core\compiler\stencil.js
       Build: 1760088209
     Stencil: 4.38.1
  TypeScript: 5.9.3
      Rollup: 4.34.9
      Parse5: 7.2.1
      jQuery: 4.0.0-pre
      Terser: 5.37.0

Steps to Reproduce

Just clone https://github.com/MathisPct/stenciljs-4.38.1-ts-build-error-html-element and follow the readme

Code Reproduction URL

https://github.com/MathisPct/stenciljs-4.38.1-ts-build-error-html-element

Additional Information

No response

Metadata

Metadata

Assignees

Labels

Bug: ValidatedThis PR or Issue is verified to be a bug within Stencil

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions