Skip to content

inject of ElementRef does not use generic type for the returned type inference #53894

@pkozlowski-opensource

Description

@pkozlowski-opensource

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

core

Is this a regression?

No

Description

Consider the example injection of the ElementRef with a specified generic type:

  // OK: hostEl is of type ElementRef<HTMLElement>, as expected
  hostElExplicit = inject<ElementRef<HTMLElement>>(ElementRef);

  // KO: hostEl is of type ElementRef<any>, expecting ElementRef<HTMLElement>
  hostElInfered = inject(ElementRef<HTMLElement>);

Ideally inject(ElementRef<HTMLElement>) would have the return type of ElementRef<HTMLElement>.

The fix is likely around the type definition for the ProviderToken.

Please provide a link to a minimal reproduction of the bug

https://stackblitz.com/edit/stackblitz-starters-p38xn9

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgentarea: coreIssues related to the framework runtimebugcore: dicross-cutting: types

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions