Skip to content

BUG: typeCheckHostBindings: true not infering type correctly for host directive output #62783

Closed

Description

@kukjevov

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

core

Is this a regression?

No

Description

When you enable typeCheckHostBindings in tsconfig compilation will fail for working code for code that works otherwise. When you attach directive with output using host directives to some component and at the same time you use host to bind to this output you will receive error about parameter type.

test.directive.ts

/**
 * Test directive
 */
@Directive(
{
    selector: '[test]',
})
export class TestDirective
{
    public out: OutputEmitterRef<number> = output<number>();
}

home.component.ts

/**
 * Home component
 */
@Component(
{
    selector: 'home-view',
    templateUrl: 'home.component.html',
    host:
    {
        '(out)': 'showOut($event)',
    },
    hostDirectives:
    [
        {
            directive: TestDirective,
            outputs: ['out'],
        },
    ],
    changeDetection: ChangeDetectionStrategy.OnPush
})
@ComponentRedirectRoute('', 'home')
@ComponentRoute({path: 'home'})
@WithScrollableCssClass()
export class HomeComponent
{
    public showOut(val: number): void
    {
        console.log('out', val);
    }
}

As you can see you have output of type number and event listener with same parameter type, so you are trying to assign number to number, but you will receive error Argument of type 'Event' is not assignable to parameter of type 'number'.

Minimal reproduction:

  • git clone https://github.com/kukjevov/ng-universal-demo.git demo
  • cd demo
  • git checkout bug/2.0
  • npm install
  • npm start
  • and you can see compilation error in console

Please provide a link to a minimal reproduction of the bug

No response

Please provide the exception or error you saw

Argument of type 'Event' is not assignable to parameter of type 'number'.

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

Angular CLI: `20.1.2`
Node: `22.16.0`
Package Manager: npm `10.9.2`
OS: Windows 11 x64
Angular: `20.1.3`

Anything else?

No response

Activity

  1. added
    area: core
    on Jul 24, 2025
  2. added this to the needsTriage milestone on Jul 24, 2025
  3. scurk1415 commented on Jul 25, 2025

    @scurk1415

    Same error if the component has an output and a directive that sits on it is listening to the output event via host.

    I have a tabs component with an tabChange output. Then i have a directive that listens to the tabChange outputs and does a specific action (in my case change the route queryParams).

    @Directive({
      selector: 'app-tabs[appRouting]',
      host: {
        '(tabChange)': 'onTabChange($event)'
      }
    })
    export class TabRoutingDirective {
    
  4. added
    area: compiler
    and removed
    area: core
    on Jul 30, 2025
  5. self-assigned this
    on Aug 2, 2025
  6. added 4 commits that reference this issue on Aug 2, 2025
    eb76682
    49fd593
    dfcca8f
    35f1f18
  7. JoostK commented on Aug 4, 2025

    @JoostK
    Member

    Same error if the component has an output and a directive that sits on it is listening to the output event via host.

    I have a tabs component with an tabChange output. Then i have a directive that listens to the tabChange outputs and does a specific action (in my case change the route queryParams).

    @Directive({
      selector: 'app-tabs[appRouting]',
      host: {
        '(tabChange)': 'onTabChange($event)'
      }
    })
    export class TabRoutingDirective {
    

    Note that this will not be supported with #62965, as any such directives are non-local to the directive/component and can therefore not be included in its type-checking context.

  8. added a commit that references this issue on Aug 5, 2025
    3b2e8ef
  9. added a commit that references this issue on Aug 5, 2025
    fb1fc82
  10. angular-automatic-lock-bot commented on Sep 5, 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.

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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions