Skip to content

Commit c87daed

Browse files
authored
feat: added default type value for modal return value (#254)
1 parent fe332ad commit c87daed

File tree

4 files changed

+20
-17
lines changed

4 files changed

+20
-17
lines changed

packages/components/modal/modal-ref.class.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { KbqModalComponent } from './modal.component';
55
* API class that public to users to handle the modal instance.
66
* KbqModalRef is aim to avoid accessing to the modal instance directly by users.
77
*/
8-
export abstract class KbqModalRef<C = any, R = any> {
8+
export abstract class KbqModalRef<C = any, R = unknown> {
99
abstract afterOpen: Observable<void>;
1010
abstract afterClose: Observable<R>;
1111

packages/components/modal/modal.service.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export class KbqModalService {
8686
this.modalControl.closeAll();
8787
}
8888

89-
create<C, R>(options: IModalOptionsForService<C> = {}): KbqModalRef<C, R> {
89+
create<C, R = unknown>(options: IModalOptionsForService<C> = {}): KbqModalRef<C, R> {
9090
if (typeof options.kbqOnCancel !== 'function') {
9191
// Leave a empty function to close this modal by default
9292
options.kbqOnCancel = () => {};
@@ -111,7 +111,10 @@ export class KbqModalService {
111111
return new ModalBuilderForService(this.overlay, options).getInstance()!;
112112
}
113113

114-
confirm<C, R>(options: IModalOptionsForService<C> = {}, confirmType: ConfirmType = 'confirm'): KbqModalRef<C, R> {
114+
confirm<C, R = unknown>(
115+
options: IModalOptionsForService<C> = {},
116+
confirmType: ConfirmType = 'confirm'
117+
): KbqModalRef<C, R> {
115118
if ('kbqFooter' in options) {
116119
console.warn(`The Confirm-Modal doesn't support "kbqFooter", this property will be ignored.`);
117120
}
@@ -128,17 +131,17 @@ export class KbqModalService {
128131
return this.create<C, R>(options);
129132
}
130133

131-
open<C, R>(options: IModalOptionsForService<C> = {}): KbqModalRef<C, R> {
134+
open<C, R = unknown>(options: IModalOptionsForService<C> = {}): KbqModalRef<C, R> {
132135
options.kbqModalType = 'custom';
133136

134137
return this.create<C, R>(options);
135138
}
136139

137-
success<C, R>(options: IModalOptionsForService<C> = {}): KbqModalRef<C, R> {
140+
success<C, R = unknown>(options: IModalOptionsForService<C> = {}): KbqModalRef<C, R> {
138141
return this.confirm<C, R>(options, 'success');
139142
}
140143

141-
delete<C, R>(options: IModalOptionsForService<C> = {}): KbqModalRef<C, R> {
144+
delete<C, R = unknown>(options: IModalOptionsForService<C> = {}): KbqModalRef<C, R> {
142145
return this.confirm<C, R>(options, 'warn');
143146
}
144147
}

packages/docs-examples/components/modal/modal-component/modal-component-example.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,24 @@ import { KbqModalRef, KbqModalService } from '@koobiq/components/modal';
1111
encapsulation: ViewEncapsulation.None
1212
})
1313
export class ModalComponentExample {
14-
componentModal: KbqModalRef;
14+
modalRef: KbqModalRef<KbqModalCustomComponent, 'save' | 'close'>;
1515

1616
constructor(private modalService: KbqModalService) {}
1717

1818
openModal() {
19-
this.componentModal = this.modalService.open({
19+
this.modalRef = this.modalService.open({
2020
kbqComponent: KbqModalCustomComponent,
2121
kbqComponentParams: {
2222
title: 'Title',
2323
subtitle: 'Subtitle'
2424
}
2525
});
2626

27-
this.componentModal.afterOpen.subscribe(() => {
27+
this.modalRef.afterOpen.subscribe(() => {
2828
console.log('[afterOpen] emitted!');
2929
});
3030

31-
this.componentModal.afterClose.subscribe((action: 'save' | 'close') => {
31+
this.modalRef.afterClose.subscribe((action) => {
3232
console.log(`[afterClose] emitted, chosen action: ${action}`);
3333
});
3434
}
@@ -76,7 +76,7 @@ export class KbqModalCustomComponent {
7676
@Input() title: string;
7777
@Input() subtitle: string;
7878

79-
constructor(private modal: KbqModalRef) {}
79+
constructor(private modal: KbqModalRef<KbqModalCustomComponent, 'save' | 'close'>) {}
8080

8181
destroyModal(action: 'save' | 'close') {
8282
this.modal.destroy(action);

tools/public_api_guard/components/modal.api.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ export class KbqModalModule {
274274
}
275275

276276
// @public
277-
export abstract class KbqModalRef<C = any, R = any> {
277+
export abstract class KbqModalRef<C = any, R = unknown> {
278278
// (undocumented)
279279
abstract afterClose: Observable<R>;
280280
// (undocumented)
@@ -302,17 +302,17 @@ export class KbqModalService {
302302
// (undocumented)
303303
closeAll(): void;
304304
// (undocumented)
305-
confirm<C, R>(options?: IModalOptionsForService<C>, confirmType?: ConfirmType): KbqModalRef<C, R>;
305+
confirm<C, R = unknown>(options?: IModalOptionsForService<C>, confirmType?: ConfirmType): KbqModalRef<C, R>;
306306
// (undocumented)
307-
create<C, R>(options?: IModalOptionsForService<C>): KbqModalRef<C, R>;
307+
create<C, R = unknown>(options?: IModalOptionsForService<C>): KbqModalRef<C, R>;
308308
// (undocumented)
309-
delete<C, R>(options?: IModalOptionsForService<C>): KbqModalRef<C, R>;
309+
delete<C, R = unknown>(options?: IModalOptionsForService<C>): KbqModalRef<C, R>;
310310
// (undocumented)
311-
open<C, R>(options?: IModalOptionsForService<C>): KbqModalRef<C, R>;
311+
open<C, R = unknown>(options?: IModalOptionsForService<C>): KbqModalRef<C, R>;
312312
// (undocumented)
313313
get openModals(): KbqModalRef[];
314314
// (undocumented)
315-
success<C, R>(options?: IModalOptionsForService<C>): KbqModalRef<C, R>;
315+
success<C, R = unknown>(options?: IModalOptionsForService<C>): KbqModalRef<C, R>;
316316
// (undocumented)
317317
static ɵfac: i0.ɵɵFactoryDeclaration<KbqModalService, never>;
318318
// (undocumented)

0 commit comments

Comments
 (0)