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 Oct 17, 2023
1 parent df17d50 commit a147cef
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 @@ -57,7 +57,7 @@ const BACKDROP_ATTRIBUTES: string[] = ['animation', 'backdropClass'];
/**
* 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 Down Expand Up @@ -97,7 +97,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 @@ -1501,7 +1501,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 @@ -23,7 +23,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._injector, content, combinedOptions);
}
Expand Down

0 comments on commit a147cef

Please sign in to comment.