Skip to content

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

@sod

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

Metadata

Metadata

Assignees

Labels

P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgentarea: commonIssues related to APIs in the @angular/common packagebugcross-cutting: typesstate: has PR

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions