Skip to content

Commit

Permalink
fix(modal): add typing for modalRef.componentInstance (#2815)
Browse files Browse the repository at this point in the history
Fixes #2479
  • Loading branch information
michaeljota authored and maxokorokov committed Oct 21, 2019
1 parent 7a584ad commit f450a7c
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/modal/modal-ref.ts
Expand Up @@ -30,7 +30,7 @@ export class NgbActiveModal {
/**
* A reference to the newly opened modal returned by the `NgbModal.open()` method.
*/
export class NgbModalRef {
export class NgbModalRef<T = any> {
private _resolve: (result?: any) => void;
private _reject: (reason?: any) => void;

Expand All @@ -39,7 +39,7 @@ export class NgbModalRef {
*
* When a `TemplateRef` is used as the content or when the modal is closed, will return `undefined`.
*/
get componentInstance(): any {
get componentInstance(): T extends new (...args: any[]) => any? InstanceType<T>: undefined {
if (this._contentRef && this._contentRef.componentRef) {
return this._contentRef.componentRef.instance;
}
Expand Down
2 changes: 1 addition & 1 deletion src/modal/modal.spec.ts
Expand Up @@ -1087,7 +1087,7 @@ export class WithSkipTabindexFirstFocusableModalCmpt {
})
class TestComponent {
name = 'World';
openedModal: NgbModalRef;
openedModal: NgbModalRef<string>;
show = true;
@ViewChild('content', {static: true}) tplContent;
@ViewChild('destroyableContent', {static: true}) tplDestroyableContent;
Expand Down
2 changes: 1 addition & 1 deletion src/modal/modal.ts
Expand Up @@ -25,7 +25,7 @@ export class NgbModal {
*
* Also see the [`NgbModalOptions`](#/components/modal/api#NgbModalOptions) for the list of supported options.
*/
open(content: any, options: NgbModalOptions = {}): NgbModalRef {
open<T>(content: T, options: NgbModalOptions = {}): NgbModalRef<T> {
const combinedOptions = Object.assign({}, this._config, options);
return this._modalStack.open(this._moduleCFR, this._injector, content, combinedOptions);
}
Expand Down

0 comments on commit f450a7c

Please sign in to comment.