Skip to content

*ngComponentOutlet types don't allow null/undefined, even though it supports it #45716

Closed

Description

@sod

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

common

Is this a regression?

No (it's like this since forever, the ngComponentOutlet directive was created before angular could check for strictNullChecks)

Description

<ng-container *ngComponentOutlet="null"></ng-container> throws

 error TS2322: Type 'null' is not assignable to type 'Type<any>'.

even though the directive is capable of handling falsy values: https://github.com/angular/angular/blob/master/packages/common/src/directives/ng_component_outlet.ts#L99

This forces you to use any if you use ngComponentOutlet & strict null checks to render a component that is optional.

Please change

- @Input() ngComponentOutlet!: Type<any>;
+ @Input() ngComponentOutlet?: Type<any>;

in https://github.com/angular/angular/blob/master/packages/common/src/directives/ng_component_outlet.ts#L73

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

angular 13.3.4

Activity

  1. added
    area: common
    on Apr 21, 2022
  2. added this to the needsTriage milestone on Apr 21, 2022
  3. jfcere commented on May 2, 2022

    @jfcere

    image

    Reference: https://angular.io/api/common/NgComponentOutlet

    To represent a "falsy" value it should allow both undefined and null values...

    - @Input() ngComponentOutlet!: Type<any>;
    + @Input() ngComponentOutlet?: Type<any> | null;
  4. added
    P3
    on May 16, 2022
  5. modified the milestones: needsTriage, Backlog on May 16, 2022
  6. self-assigned this
    on Jun 7, 2022
  7. added a commit that references this issue on Jun 9, 2022
    ef5cba3
  8. angular-automatic-lock-bot commented on Jul 10, 2022

    @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 Jul 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P3area: commonbugcross-cutting: typesstate: has PR

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions