feature request
MatDialogRef.afterClosed() return Observable of a type other thanany.
MatDialogRef.afterClosed() returns Observable<any>.
type safety
all
I tried:
export interface DialogComponent<R> { }
export interface TypedMatDialogRef<T extends DialogComponent<R>, R> extends MatDialogRef<T> {
afterClosed(): Observable<R>;
}
export interface TypedMatDialog extends MatDialog {
open<T extends DialogComponent<R>, R, D = any>(componentOrTemplateRef: ComponentType<T>, config?: MatDialogConfig<D>): TypedMatDialogRef<T, R>;
}
@Component({})
export class MyDialogComponent implements DialogComponent<string> { }
(this.dialog as TypedMatDialog).open(MyDialogComponent)
.afterClosed()
.subscribe(string => {/* string is showing as {}*/});
Not sure why this doesn't work.
Will there be an example of how to utilize?
@crisbeto @andrewseguin To add to @gatimus I don't see any examples of this in the docs. Could you provide a quick sample here and consider adding something to the docs?
Here's a quick example of defining the result type: https://stackblitz.com/edit/angular-iw4975?file=app/dialog-overview-example.ts
Note that result is typed as string via let dialogRef: MatDialogRef<DialogOverviewExampleDialog, string>
If you try changing it to number, you'll see an error show up when you try to assign result to animal which demonstrates that it is typing correctly.
i would hardly call that a type safe dialog
when it automates the form and the template based on ANY interface automagically without having to key in every named field then it will be type safe
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
_This action has been performed automatically by a bot._
Most helpful comment
Here's a quick example of defining the result type: https://stackblitz.com/edit/angular-iw4975?file=app/dialog-overview-example.ts
Note that result is typed as string via
let dialogRef: MatDialogRef<DialogOverviewExampleDialog, string>If you try changing it to
number, you'll see an error show up when you try to assignresulttoanimalwhich demonstrates that it is typing correctly.