-
Notifications
You must be signed in to change notification settings - Fork 27.1k
Closed
Labels
area: coreIssues related to the framework runtimeIssues related to the framework runtimecross-cutting: signalsstate: has PR
Milestone
Description
Which @angular/* package(s) are relevant/related to the feature request?
core
Description
I just tried out the new viewChild() function, with the { read: ElementRef } option. Usually I use ElementRef with a generic type, i.e. ElementRef<HTMLElement> to have better type safety. I tried to set a generic type:
myViewChild = viewChild(MyComponent, { read: ElementRef<HTMLElement> });But this throws me an error:
TS-991011: Query "read" option expected a literal class reference. [plugin angular-compiler]
After removing the generic type, the error is gone, however the signal will infer type Signal<ElementRef<any> | undefined>. I want to replace the any type with a proper type.
Proposed solution
The viewChild() function offers a possibility to set the generic type of the ElementRef.
Alternatives considered
For now I'm overriding the type of the signal, but this looks quite verbose:
myViewChild: Signal<ElementRef<HTMLElement> | undefined> = viewChild(MyComponent, { read: ElementRef });Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
area: coreIssues related to the framework runtimeIssues related to the framework runtimecross-cutting: signalsstate: has PR