Skip to content

Output migration transforms eventEmitter.emit() into invalid output.emit() #58650

Closed

Description

@cexbrayat

Which @angular/* package(s) are the source of the bug?

core

Is this a regression?

Yes

Description

The output migration transforms:

@Output() eventEmitter = new EventEmitter<string>();

// later
eventEmitter.emit();

into

eventEmitter = output<string>();

// later
eventEmitter.emit();

But the value is mandatory in the output.emit signature, so the application breaks.
The migration could generate emit(undefined) in that case, or add a TODO or only treat this in with the --best-effort-mode option.

To repro, in the following Stackblitz, run:

ng g @angular/core:signals --migrations=outputs --path=./ --no-best-effort-mode

Please provide a link to a minimal reproduction of the bug

https://stackblitz.com/edit/stackblitz-starters-h5tea2?file=src%2Fmain.ts

Please provide the exception or error you saw

✘ [ERROR] TS2554: Expected 1 arguments, but got 0. [plugin angular-compiler]

    src/main.ts:18:22:
      18 │     this.eventEmitter.emit();
         ╵                       ~~~~

  An argument for 'value' was not provided.

    node_modules/@angular/core/index.d.ts:8288:9:
      8288 │     emit(value: T): void;

Please provide the environment you discovered this bug in (run ng version)

Angular CLI: 19.0.0-rc.1
Node: 18.20.3
Package Manager: npm 10.2.3
OS: linux x64

Angular: 19.0.0-rc.1
... animations, cli, common, compiler, compiler-cli, core, forms
... platform-browser, router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1900.0-rc.1
@angular-devkit/build-angular   19.0.0-rc.1
@angular-devkit/core            19.0.0-rc.1
@angular-devkit/schematics      19.0.0-rc.1
@schematics/angular             19.0.0-rc.1
rxjs                            7.8.1
typescript                      5.5.4
zone.js                         0.14.10

Anything else?

No response

Activity

  1. added
    area: migrations
    on Nov 14, 2024
  2. added this to the needsTriage milestone on Nov 14, 2024
  3. devversion commented on Nov 14, 2024

    @devversion
    Member

    I agree that we could add a TODO, or skip in "safe mode", but IMO it would also be acceptable to say that we are intentionally breaking here and surfacing a real brittle problem in the user code (caused by the bad typings of EventEmitter clearly).

    @Output() eventEmitter = new EventEmitter<string>();
    
    // later
    eventEmitter.emit();

    can already break in subtle ways at runtime, given undefined being used as value, but eventEmitter.subscribe only receiving values of type string.

  4. jnizet commented on Nov 14, 2024

    @jnizet
    Contributor

    I would also prefer the code to break. IMO, that's clearly a bug that should be fixed.
    BTW, another godd thing to do woulmd be to document what happens when emit is called without argument: does the parent component receive an undefined (and thus incorrectly typed) event? Is undefined somehow filtered out?

  5. pkozlowski-opensource commented on Nov 14, 2024

    @pkozlowski-opensource
    Member

    I agree that we could add a TODO, or skip in "safe mode", but IMO it would also be acceptable to say that we are intentionally breaking here and surfacing a real brittle problem in the user code

    This was my thinking while authoring this migration. I've marked this issue as a "bug" so we can insert a TODO indicating why it is breaking / what a user should do in this case.

  6. added a commit that references this issue on Apr 8, 2025
    f2bfa31
  7. added a commit that references this issue on Apr 8, 2025
    39a4e00
  8. angular-automatic-lock-bot commented on May 9, 2025

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  9. locked and limited conversation to collaborators on May 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area: migrationsbug

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions