Skip to content

Commit

Permalink
fix(modal): add typing for modalRef.componentInstance (ng-bootstrap…
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeljota authored and gentoo90 committed Jan 30, 2022
1 parent b4bb7dc commit 8a8fc1e
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 @@ -34,7 +34,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 _closed = new Subject<any>();
private _dismissed = new Subject<any>();
private _hidden = new Subject<void>();
Expand All @@ -46,7 +46,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 @@ -1216,7 +1216,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 = {...this._config, animation: this._config.animation, ...options};
return this._modalStack.open(this._moduleCFR, this._injector, content, combinedOptions);
}
Expand Down

0 comments on commit 8a8fc1e

Please sign in to comment.