Skip to content

Commit d3d9aac

Browse files
harunurhanchuckjaz
authored andcommitted
feat(core): optional generic type for ElementRef (#20765)
Add optional, backwards compatible generic type to `ElementRef` to support typed `nativeElement` Fix #13139 PR Close #20765
1 parent 1ccc324 commit d3d9aac

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

packages/core/src/linker/element_ref.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
// Note: We don't expose things like `Injector`, `ViewContainer`, ... here,
2222
// i.e. users have to ask for what they need. With that, we can build better analysis tools
2323
// and could do better codegen in the future.
24-
export class ElementRef {
24+
export class ElementRef<T = any> {
2525
/**
2626
* The underlying native element or `null` if direct access to native elements is not supported
2727
* (e.g. when the application runs in a web worker).
@@ -43,7 +43,7 @@ export class ElementRef {
4343
* </div>
4444
* @stable
4545
*/
46-
public nativeElement: any;
46+
public nativeElement: T;
4747

48-
constructor(nativeElement: any) { this.nativeElement = nativeElement; }
48+
constructor(nativeElement: T) { this.nativeElement = nativeElement; }
4949
}

tools/public_api_guard/core/core.d.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -362,9 +362,9 @@ export interface DoCheck {
362362
}
363363

364364
/** @stable */
365-
export declare class ElementRef {
366-
/** @stable */ nativeElement: any;
367-
constructor(nativeElement: any);
365+
export declare class ElementRef<T = any> {
366+
/** @stable */ nativeElement: T;
367+
constructor(nativeElement: T);
368368
}
369369

370370
/** @experimental */

0 commit comments

Comments
 (0)