From ffc129e8cedcd67c55d4403e61e62a6a8f886de9 Mon Sep 17 00:00:00 2001 From: Michael De Abreu Date: Thu, 18 Oct 2018 14:56:25 -0400 Subject: [PATCH] feat(modal): set strong typing in componentInstance getter property --- src/modal/modal-ref.ts | 4 ++-- src/modal/modal-stack.ts | 6 +++--- src/modal/modal.spec.ts | 2 +- src/modal/modal.ts | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/modal/modal-ref.ts b/src/modal/modal-ref.ts index 094a05b6c7..d2f70523bc 100644 --- a/src/modal/modal-ref.ts +++ b/src/modal/modal-ref.ts @@ -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 { private _resolve: (result?: any) => void; private _reject: (reason?: any) => void; @@ -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 : undefined { if (this._contentRef && this._contentRef.componentRef) { return this._contentRef.componentRef.instance; } diff --git a/src/modal/modal-stack.ts b/src/modal/modal-stack.ts index 5cda3d2408..c66b863012 100644 --- a/src/modal/modal-stack.ts +++ b/src/modal/modal-stack.ts @@ -44,7 +44,7 @@ export class NgbModalStack { }); } - open(moduleCFR: ComponentFactoryResolver, contentInjector: Injector, content: any, options): NgbModalRef { + open(moduleCFR: ComponentFactoryResolver, contentInjector: Injector, content: T, options): NgbModalRef { const containerEl = isDefined(options.container) ? this._document.querySelector(options.container) : this._document.body; const renderer = this._rendererFactory.createRenderer(null, null); @@ -68,7 +68,7 @@ export class NgbModalStack { let backdropCmptRef: ComponentRef = options.backdrop !== false ? this._attachBackdrop(moduleCFR, containerEl) : null; let windowCmptRef: ComponentRef = this._attachWindowComponent(moduleCFR, containerEl, contentRef); - let ngbModalRef: NgbModalRef = new NgbModalRef(windowCmptRef, contentRef, backdropCmptRef, options.beforeDismiss); + let ngbModalRef: NgbModalRef = new NgbModalRef(windowCmptRef, contentRef, backdropCmptRef, options.beforeDismiss); this._registerModalRef(ngbModalRef); this._registerWindowCmpt(windowCmptRef); @@ -197,7 +197,7 @@ export class NgbModalStack { this._ariaHiddenValues.clear(); } - private _registerModalRef(ngbModalRef: NgbModalRef) { + private _registerModalRef(ngbModalRef: NgbModalRef) { const unregisterModalRef = () => { const index = this._modalRefs.indexOf(ngbModalRef); if (index > -1) { diff --git a/src/modal/modal.spec.ts b/src/modal/modal.spec.ts index 6db15a5722..bce49e5caa 100644 --- a/src/modal/modal.spec.ts +++ b/src/modal/modal.spec.ts @@ -1087,7 +1087,7 @@ export class WithSkipTabindexFirstFocusableModalCmpt { }) class TestComponent { name = 'World'; - openedModal: NgbModalRef; + openedModal: NgbModalRef; show = true; @ViewChild('content', {static: true}) tplContent; @ViewChild('destroyableContent', {static: true}) tplDestroyableContent; diff --git a/src/modal/modal.ts b/src/modal/modal.ts index 38e832d0a7..6f438b3cd9 100644 --- a/src/modal/modal.ts +++ b/src/modal/modal.ts @@ -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(content: T, options: NgbModalOptions = {}): NgbModalRef { const combinedOptions = Object.assign({}, this._config, options); return this._modalStack.open(this._moduleCFR, this._injector, content, combinedOptions); }