diff --git a/src/modal/modal-ref.ts b/src/modal/modal-ref.ts index ced3e4b8b2..61a960ba4a 100644 --- a/src/modal/modal-ref.ts +++ b/src/modal/modal-ref.ts @@ -24,7 +24,7 @@ export class NgbActiveModal { /** * A reference to a newly opened modal. */ -export class NgbModalRef { +export class NgbModalRef { private _resolve: (result?: any) => void; private _reject: (reason?: any) => void; @@ -32,7 +32,7 @@ export class NgbModalRef { * The instance of component used as modal's content. * Undefined when a TemplateRef is used as modal's content. */ - get componentInstance(): any { + get componentInstance(): T extends new (...args: any[]) => any ? InstanceType : undefined { if (this._contentRef.componentRef) { return this._contentRef.componentRef.instance; } diff --git a/src/modal/modal-stack.ts b/src/modal/modal-stack.ts index c7b7f58e76..0c9d63a69d 100644 --- a/src/modal/modal-stack.ts +++ b/src/modal/modal-stack.ts @@ -39,7 +39,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); @@ -61,7 +61,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); @@ -159,7 +159,7 @@ export class NgbModalStack { return new ContentRef([[componentRef.location.nativeElement]], componentRef.hostView, componentRef); } - 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 0f0af6844b..60cd283a3a 100644 --- a/src/modal/modal.spec.ts +++ b/src/modal/modal.spec.ts @@ -914,7 +914,7 @@ export class WithFirstFocusableModalCmpt { }) class TestComponent { name = 'World'; - openedModal: NgbModalRef; + openedModal: NgbModalRef; show = true; @ViewChild('content') tplContent; @ViewChild('destroyableContent') tplDestroyableContent; diff --git a/src/modal/modal.ts b/src/modal/modal.ts index d669b2bbe4..8f1b08a009 100644 --- a/src/modal/modal.ts +++ b/src/modal/modal.ts @@ -20,7 +20,7 @@ export class NgbModal { * components can be injected with an instance of the NgbActiveModal class. You can use methods on the * NgbActiveModal class to close / dismiss modals from "inside" of a component. */ - 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); }