Skip to content

Commit 47a8f76

Browse files
crisbetojelbourn
authored andcommitted
refactor(portal): make TemplatePortal generic param optional (#9272)
Makes the `C` generic param on the `TemplatePortal` optional, because it's only being used to type the `context` property which is optional itself. Also does some minor cleanup in the `TemplatePortal`.
1 parent 7672913 commit 47a8f76

File tree

10 files changed

+15
-16
lines changed

10 files changed

+15
-16
lines changed

src/cdk/overlay/overlay-directives.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export class CdkOverlayOrigin {
9595
})
9696
export class CdkConnectedOverlay implements OnDestroy, OnChanges {
9797
private _overlayRef: OverlayRef;
98-
private _templatePortal: TemplatePortal<any>;
98+
private _templatePortal: TemplatePortal;
9999
private _hasBackdrop = false;
100100
private _backdropSubscription = Subscription.EMPTY;
101101
private _positionSubscription = Subscription.EMPTY;

src/cdk/overlay/overlay.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
describe('Overlay', () => {
2121
let overlay: Overlay;
2222
let componentPortal: ComponentPortal<PizzaMsg>;
23-
let templatePortal: TemplatePortal<any>;
23+
let templatePortal: TemplatePortal;
2424
let overlayContainerElement: HTMLElement;
2525
let overlayContainer: OverlayContainer;
2626
let viewContainerFixture: ComponentFixture<TestComponentWithTemplatePortals>;

src/cdk/portal/portal-directives.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import {Portal, TemplatePortal, ComponentPortal, BasePortalOutlet} from './porta
3131
selector: '[cdk-portal], [cdkPortal], [portal]',
3232
exportAs: 'cdkPortal',
3333
})
34-
export class CdkPortal extends TemplatePortal<any> {
34+
export class CdkPortal extends TemplatePortal {
3535
constructor(templateRef: TemplateRef<any>, viewContainerRef: ViewContainerRef) {
3636
super(templateRef, viewContainerRef);
3737
}

src/cdk/portal/portal.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,22 +107,21 @@ export class ComponentPortal<T> extends Portal<ComponentRef<T>> {
107107
/**
108108
* A `TemplatePortal` is a portal that represents some embedded template (TemplateRef).
109109
*/
110-
export class TemplatePortal<C> extends Portal<C> {
110+
export class TemplatePortal<C = any> extends Portal<C> {
111111
/** The embedded template that will be used to instantiate an embedded View in the host. */
112112
templateRef: TemplateRef<C>;
113113

114114
/** Reference to the ViewContainer into which the template will be stamped out. */
115115
viewContainerRef: ViewContainerRef;
116116

117+
/** Contextual data to be passed in to the embedded view. */
117118
context: C | undefined;
118119

119-
constructor(template: TemplateRef<any>, viewContainerRef: ViewContainerRef, context?: C) {
120+
constructor(template: TemplateRef<C>, viewContainerRef: ViewContainerRef, context?: C) {
120121
super();
121122
this.templateRef = template;
122123
this.viewContainerRef = viewContainerRef;
123-
if (context) {
124-
this.context = context;
125-
}
124+
this.context = context;
126125
}
127126

128127
get origin(): ElementRef {

src/lib/autocomplete/autocomplete-trigger.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ export function getMatAutocompleteMissingPanelError(): Error {
117117
})
118118
export class MatAutocompleteTrigger implements ControlValueAccessor, OnDestroy {
119119
private _overlayRef: OverlayRef | null;
120-
private _portal: TemplatePortal<any>;
120+
private _portal: TemplatePortal;
121121
private _panelOpen: boolean = false;
122122

123123
/** Strategy that is used to position the panel. */

src/lib/expansion/expansion-panel.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ export class MatExpansionPanel extends _MatExpansionPanelMixinBase
105105
@ContentChild(MatExpansionPanelContent) _lazyContent: MatExpansionPanelContent;
106106

107107
/** Portal holding the user's content. */
108-
_portal: TemplatePortal<any>;
108+
_portal: TemplatePortal;
109109

110110
constructor(@Optional() @Host() accordion: MatAccordion,
111111
_changeDetectorRef: ChangeDetectorRef,
@@ -144,7 +144,7 @@ export class MatExpansionPanel extends _MatExpansionPanelMixinBase
144144
filter(() => this.expanded && !this._portal),
145145
take(1)
146146
).subscribe(() => {
147-
this._portal = new TemplatePortal<any>(this._lazyContent._template, this._viewContainerRef);
147+
this._portal = new TemplatePortal(this._lazyContent._template, this._viewContainerRef);
148148
});
149149
}
150150
}

src/lib/menu/menu-trigger.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export const MENU_PANEL_TOP_PADDING = 8;
8383
exportAs: 'matMenuTrigger'
8484
})
8585
export class MatMenuTrigger implements AfterContentInit, OnDestroy {
86-
private _portal: TemplatePortal<any>;
86+
private _portal: TemplatePortal;
8787
private _overlayRef: OverlayRef | null = null;
8888
private _menuOpen: boolean = false;
8989
private _closeSubscription = Subscription.EMPTY;

src/lib/tabs/tab-body.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ describe('MatTabBody', () => {
156156
`
157157
})
158158
class SimpleTabBodyApp {
159-
content: TemplatePortal<any>;
159+
content: TemplatePortal;
160160
position: number;
161161
origin: number;
162162

src/lib/tabs/tab-body.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ export class MatTabBody implements OnInit {
131131
@Output() _onCentered: EventEmitter<void> = new EventEmitter<void>(true);
132132

133133
/** The tab body content to display. */
134-
@Input('content') _content: TemplatePortal<any>;
134+
@Input('content') _content: TemplatePortal;
135135

136136
/** The shifted index position of the tab body, where zero represents the active center tab. */
137137
@Input()

src/lib/tabs/tab.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ export class MatTab extends _MatTabMixinBase implements OnInit, CanDisable, OnCh
5252
@Input('label') textLabel: string = '';
5353

5454
/** The portal that will be the hosted content of the tab */
55-
private _contentPortal: TemplatePortal<any> | null = null;
55+
private _contentPortal: TemplatePortal | null = null;
5656

5757
/** @docs-private */
58-
get content(): TemplatePortal<any> | null {
58+
get content(): TemplatePortal | null {
5959
return this._contentPortal;
6060
}
6161

0 commit comments

Comments
 (0)