Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(modal): set strong typing in componentInstance getter property #2815

Merged
merged 1 commit into from Oct 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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