From e23b1546cf019f90fcb3d1eedd768408e1ebe1c6 Mon Sep 17 00:00:00 2001 From: crisbeto Date: Thu, 7 Dec 2017 19:11:10 +0100 Subject: [PATCH] fix(dialog): improved type safety in dialog ref result Adds an extra generic param to the `MatDialogRef` that allows consumers to type the result that is passed to `close`, as well as the value in the `beforeClosed` and `afterClosed` observables. Fixes #8760. --- src/lib/dialog/dialog-ref.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/lib/dialog/dialog-ref.ts b/src/lib/dialog/dialog-ref.ts index e3b37957847c..eca66383beb9 100644 --- a/src/lib/dialog/dialog-ref.ts +++ b/src/lib/dialog/dialog-ref.ts @@ -23,7 +23,7 @@ let uniqueId = 0; /** * Reference to a dialog opened via the MatDialog service. */ -export class MatDialogRef { +export class MatDialogRef { /** The instance of component opened into the dialog. */ componentInstance: T; @@ -34,13 +34,13 @@ export class MatDialogRef { private _afterOpen = new Subject(); /** Subject for notifying the user that the dialog has finished closing. */ - private _afterClosed = new Subject(); + private _afterClosed = new Subject(); /** Subject for notifying the user that the dialog has started closing. */ - private _beforeClose = new Subject(); + private _beforeClose = new Subject(); /** Result to be passed to afterClosed. */ - private _result: any; + private _result: R | undefined; constructor( private _overlayRef: OverlayRef, @@ -74,7 +74,7 @@ export class MatDialogRef { * Close the dialog. * @param dialogResult Optional result to return to the dialog opener. */ - close(dialogResult?: any): void { + close(dialogResult?: R): void { this._result = dialogResult; // Transition the backdrop in parallel to the dialog. @@ -101,14 +101,14 @@ export class MatDialogRef { /** * Gets an observable that is notified when the dialog is finished closing. */ - afterClosed(): Observable { + afterClosed(): Observable { return this._afterClosed.asObservable(); } /** * Gets an observable that is notified when the dialog has started closing. */ - beforeClose(): Observable { + beforeClose(): Observable { return this._beforeClose.asObservable(); }