Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: broken codegen for collections of named types in EventEmitter #405

Open
3 tasks done
aniederer-chatham opened this issue Dec 7, 2023 · 1 comment
Open
3 tasks done
Labels
help wanted a good issue for the community package: angular @stencil/angular-output-target package type: bug Something isn't working

Comments

@aniederer-chatham
Copy link

aniederer-chatham commented Dec 7, 2023

Prerequisites

Stencil Version

4.8.1

Stencil Framework Output Target

Angular

Stencil Framework Output Target Version

0.8.3

Current Behavior

The emitted type for AppRoot is

export declare interface AppRoot extends Components.AppRoot {
  e: EventEmitter<CustomEvent<IAppRoot{ a: [object Object]; }>>;
}

which is invalid TypeScript

Expected Behavior

The emitted type for AppRoot is

export declare interface AppRoot extends Components.AppRoot {
  e: EventEmitter<CustomEvent<{ a: IAppRootA; }>>;
}

Steps to Reproduce

  • Pull the repro repo and run npm run build in the repo root
  • Open the generated file at /angular-output-target/projects/stencil-components/src/lib/components.ts
  • Go to line 33 or search for "export declare interface AppRoot"
  • Notice the invalid syntax emitted for the type of AppRoot#e

The component which causes the broken codegen is defined as follows:

import { Component, Host, Event, EventEmitter, h } from '@stencil/core';

export type A = { };

@Component({ tag: 'app-root', shadow: true, })
export class AppRoot {
  @Event() readonly e!: EventEmitter<{ a: A; }>;
  render() {
    return <Host></Host>
  }
}

Another alternative definition which also exhibits the pathological behavior is as follows:

import { Component, Host, Event, EventEmitter, h } from '@stencil/core';

export type A = { };

@Component({ tag: 'app-root', shadow: true, })
export class AppRoot {
  @Event() readonly e!: EventEmitter<readonly A[]>;
  render() {
    return <Host></Host>
  }
}

Code Reproduction URL

https://github.com/aniederer-chatham/stencil-angular-type-bug-poc

Additional Information

This also occurs when the object is readonly, emitting <IAppRootreadonly {a: [object Object]; }>

This happens effectively every time you write a type that a basic search-and-replace would mess up, for example EventEmitter<readonly A[]> outputs EventEmitter<CustomEvent<IAppRootreadonly [object Object][]>>. I'm guessing the codegen there isn't very robust.

@ionitron-bot ionitron-bot bot added the triage label Dec 7, 2023
@christian-bromann christian-bromann added type: bug Something isn't working package: angular @stencil/angular-output-target package help wanted a good issue for the community and removed triage labels Oct 12, 2024
Copy link

ionitron-bot bot commented Oct 12, 2024

This issue has been labeled as help wanted. This label is added to issues that we believe would be good for contributors.

If you'd like to work on this issue, please comment here letting us know that you would like to submit a pull request for it. This helps us to keep track of the pull request and make sure there isn't duplicated effort.
Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted a good issue for the community package: angular @stencil/angular-output-target package type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants