Skip to content

Commit 83fb78e

Browse files
committed
More poking
1 parent cc1c18d commit 83fb78e

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

addon/services/toaster.ts

+15-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import Service from '@ember/service';
2-
import { tracked } from '@glimmer/tracking';
32
import { task, timeout } from 'ember-concurrency';
43
import { A, type NativeArray } from '@ember/array';
54
import type { ComponentLike } from '@glint/template';
@@ -8,29 +7,36 @@ export type ToastData = {
87
component?: ComponentLike<CustomToastSignature>;
98
title?: string;
109
message?: string;
11-
options: ToastOptions | Record<string, unknown>;
10+
options: ToastOptions | CustomToastOptions;
1211
};
1312

14-
export type ToastOptions = {
13+
interface BaseOptions {
1514
icon?: string | ComponentLike<{ Element: Element }>;
1615
closable?: boolean;
1716
timeOut?: number | null;
17+
}
18+
19+
export interface ToastOptions extends BaseOptions {
1820
type?: 'error' | 'success' | 'warning';
19-
};
21+
}
22+
23+
export interface CustomToastOptions extends BaseOptions {
24+
[key: string]: unknown; // Allows additional properties
25+
}
2026

2127
export interface CustomToastSignature {
2228
Args: {
23-
options: Record<string, unknown>;
29+
// ToastOptions shouldn't be needed, but I don't know how to do type assertions in templates
30+
options: ToastOptions | CustomToastOptions;
2431
close: () => void;
2532
};
2633
}
2734

2835
export default class ToasterService extends Service {
29-
// TS was complaining without the explicit NativeArray import and type here, not sure why.
3036
// TODO: Replace A with a regular array
31-
@tracked toasts: NativeArray<ToastData> = A<ToastData>([]);
37+
toasts: NativeArray<ToastData> = A<ToastData>([]);
3238

33-
displayToast = task(async (toast: ToastData) => {
39+
private displayToast = task(async (toast: ToastData) => {
3440
if (typeof toast.options['timeOut'] === 'undefined') {
3541
toast.options['timeOut'] = null;
3642
}
@@ -49,7 +55,7 @@ export default class ToasterService extends Service {
4955
});
5056

5157
show(
52-
component: ComponentLike<unknown>,
58+
component: ComponentLike<CustomToastSignature>,
5359
options: Record<string, unknown> = {},
5460
) {
5561
const toast = {

0 commit comments

Comments
 (0)