Skip to content

Change Element decorator name or allow typescript as syntax #2074

Closed

Description

@mboudreau

Stencil version:

I'm submitting a:
[ X ] bug report
[ ] feature request
[ ] support request => Please do not submit support requests here, use one of these channels: https://stencil-worldwide.herokuapp.com/ or https://forum.ionicframework.com/

Current behavior:
the Element decorator name is conflicting with the global Element type for DOM elements. There is no namespacing for these globals, so I can't reference them any other way, and when I tried to use the typescript as syntax for importing, stencil generated code that simply did not work while typescript isn't showing any issues. I also tried it with import * as stencil from '@stencil/core'; so I could add the decorator with @stencil.Element, but that didn't work either.

Expected behavior:
I would expect that Stencil wouldn't try to conflict with global types, or if they did, make it easy to change it to prevent this from happening. At this time, the type for my element variable is a function, which is wrong and makes it harder to develop with.

Steps to reproduce:
See code below.

Related code:

import {Component, Element, Prop, State, Watch} from '@stencil/core';
// this doesn't work: import {Element as RootElement} from '@stencil/core';
// neither does this: import * as stencil from '@stencil/core';

@Component({
    tag: 'nx-icon',
    styleUrl: `icon.scss`,
    shadow: false
})
export class IconComponent {
    @Element() rootElement: HTMLElement;
    element: Element; // trying to save a dynamically created element, but the type is the decorator function, not the DOM Element
}

Other information:

Activity

  1. Nightmaster commented on Jun 11, 2020

    @Nightmaster
    Contributor

    Another example of problematic situation with Event annotation:

    import { Component, Event, EventEmitter } from '@stencil/core'
    
    @Component()
    export class DemoComponent {
      @Event()
      myEvent: EventEmitter<never>
    
      render(): unknown {
        return <form onSubmit={ this.onFormSubmitted }/>
      }
    
      private readonly onFormSubmitted =
        (e: Event /* Fails here because it is not the correct Event interface! */): void => {
          e.stopPropagation()
          this.myEvent.emit()
        }
    }

    So a rename of the problematic elements (at least Element and Event), or the support the as syntax would be mostly appreciated!

  2. Nightmaster commented on Jun 19, 2020

    @Nightmaster
    Contributor
  3. mmakrzem commented on Sep 9, 2020

    @mmakrzem

    I have a similar problem that I reported in #2563

    Any idea's how to "fix/hack" stencil to allow me to use "Element" in my stencil components?

  4. tanner-reits commented on Jan 31, 2023

    @tanner-reits
    Contributor

    Hey all 👋

    Sorry there has been no reply from the team here. I just took a look at this with the latest version of Stencil and can confirm import aliasing is not working! Looking through the existing Stencil issue, it appears we have a few different issues related to the same problem, but #3137 seems to cover them all.

    That being said, I'll get this issue labeled accordingly for the team to track. But, I would advise keeping an eye on the mentioned issue for updates as that work progresses.

    Thanks!

  5. added
    Resolution: Refine
    and removed on Jan 31, 2023
  6. tanner-reits commented on Dec 11, 2023

    @tanner-reits
    Contributor

    Closing as duplicate of #3137

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Resolution: Refine

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions