Skip to content

Generic types of components/directives are inferred as any when some corresponding inputs are omitted #57644

Description

@yurakis

Command

serve

Is this a regression?

  • Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

No response

Description

I recently started to notice that after introducing strictTemplates and strictNullChecks in my project, WebStorm still sometimes highlights types incompatibility. So I started investigating whether it's my IDE's problem or not.

Let's assume that we have a method in component, which accepts string as an argument. If we try to call it from a template with undefined or null explicitly, compiler would throw an error. However, this is not the case when library is involved. In my example is used along with (selectedChange).

$event can be null. And if I try to call that method with $event.toString(), compiler would not complain. Even something like $event?.toString() or $event?.toString() ?? undefined or $event?.toString() || undefined would still be fine for the compiler. At the same time something like '' || undefined will trigger a compilation error.

Here is the StackBlitz link. This is a fork from the official example.

Minimal Reproduction

  • init strict application with strictTemplates & strictNullChecks
  • create component with a method, which accepts string as a single argument
  • call that method from the template using third-party library's component where $event can be null. E.g. myMethod($event.toString())

Exception or Error

This is what I would actually expect to see in such case, but no error was given.

Your Environment

Angular CLI: 18.2.1
Node: 18.20.3
Package Manager: npm 10.2.3
OS: linux x64

Angular: 18.2.2
... animations, cdk, common, compiler, compiler-cli, core, forms
... localize, material, material-moment-adapter
... platform-browser, platform-browser-dynamic, router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1802.1
@angular-devkit/build-angular   18.2.1
@angular-devkit/core            18.2.1
@angular-devkit/schematics      18.2.1
@angular/cli                    18.2.1
@schematics/angular             18.2.1
rxjs                            7.4.0
typescript                      5.5.4
zone.js                         0.14.10

Anything else relevant?

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions