ionic-team / stencil-ds-output-targets

These are output targets that can be added to Stencil for React and Angular.
https://stenciljs.com
MIT License
248 stars 112 forks source link

At directivesProxyFile the @Component decorator is missing the output event array #389

Closed adoumas closed 11 months ago

adoumas commented 1 year ago

Prerequisites

Stencil Version

3.4.1

Stencil Framework Output Target

Angular

Stencil Framework Output Target Version

0.8.2

Current Behavior

At "generate-angular-component.ts" file line 47

` @Component({

selector: '${tagName}', changeDetection: ChangeDetectionStrategy.OnPush, template: '', // eslint-disable-next-line @angular-eslint/no-inputs-metadata-property inputs: [${formattedInputs}], ${standaloneOption}

}) `

and on line 29

`

if (hasInputs) {
    proxyCmpOptions.push(`\n  inputs: [${formattedInputs}]`);
}

if (hasMethods) {
    proxyCmpOptions.push(`\n  methods: [${formattedMethods}]`);
}

`

Expected Behavior

Should be like this so we can use it on angular as event (myCustomEvent)="handleCustomEvent($event)"

` @Component({

selector: '${tagName}', changeDetection: ChangeDetectionStrategy.OnPush, template: '', // eslint-disable-next-line @angular-eslint/no-inputs-metadata-property inputs: [${formattedInputs}], outputs: [${formattedOutputs}], ${standaloneOption},

}) `

`

if (hasInputs) {
    proxyCmpOptions.push(`\n  inputs: [${formattedInputs}]`);
}

if (hasOutputs) {
    proxyCmpOptions.push(`\n  outputs: [${formattedOutputs}]`);
}

if (hasMethods) {
    proxyCmpOptions.push(`\n  methods: [${formattedMethods}]`);
}

`

Steps to Reproduce

Just try to build angularOutputTarget

Code Reproduction URL

https://github.com/ionic-team/stencil-ds-output-targets/blob/main/packages/angular-output-target/src/generate-angular-component.ts

Additional Information

I hope not to miss something and i can't use the output decorator

<my-custom-element (myCustomEvent)=""></my-custom-element>

sean-perkins commented 12 months ago

👋 can you provide a reproduction app/stencil project that experiences this problem?

We use the output target with Ionic Framework and the events are bound correctly. The outputs array will not be written if the component does not have any decorated @Event() properties.

ionitron-bot[bot] commented 12 months ago

Thanks for the issue! This issue has been labeled as needs reproduction. This label is added to issues that need a code reproduction.

Please reproduce this issue in a Stencil project and provide a way for us to access it (GitHub repo, etc). Without a reliable code reproduction, it is unlikely we will be able to resolve the issue, leading to it being closed.

If you have already provided a code snippet and are seeing this message, it is likely that the code snippet was not enough for our team to reproduce the issue.

m-thompson-code commented 11 months ago

A workaround to this issue that I've used is to define a HTMLElementTagNameMap where I define event listeners for each Event:

/** src/my-types.d.ts */
declare global {
  type EventName = "my-event";
  interface HTMLMyComponentElement {
      addEventListener<EventName>(type: EventName, listener: (this: HTMLMyComponentElement, ev: MyComponentCustomEvent<boolean>) => any, options?: boolean | AddEventListenerOptions): void;
      addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
      removeEventListener<EventName>(type: EventName, listener: (this: HTMLMyComponentElement, ev: MyComponentCustomEvent<boolean>) => any, options?: boolean | EventListenerOptions): void;
      removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;
  }

  interface HTMLElementTagNameMap {
      "my-component": HTMLMyComponentElement;
  }
}

I've created a PR to make this part of Stencil's compiler: https://github.com/ionic-team/stencil/pull/4909 And you can use this output target to generate these event listener types for your project: https://github.com/m-thompson-code/event-listener-types-output-target#event-listener-types-output-target

ionitron-bot[bot] commented 11 months ago

Thanks for the issue! This issue is being closed due to the lack of a code reproduction. If this is still an issue with the latest version of the output targets, please create a new issue and ensure the template is fully filled out.