Skip to content

Commit e1477df

Browse files
committed
refactor: 将Base类改为泛型以支持自定义选项类型
使Base类能够接受自定义的选项类型参数,提高类型安全性和灵活性
1 parent 54a655d commit e1477df

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

src/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ export interface BaseOptions<T = any> {
1313
[key: string]: any;
1414
}
1515

16-
export abstract class Base<T = any> extends ReadyEventEmitter {
17-
options: BaseOptions<T>;
16+
export abstract class Base<T = any, O extends BaseOptions<T> = BaseOptions<T>> extends ReadyEventEmitter {
17+
options: O;
1818
#closed = false;
1919
#localStorage: AsyncLocalStorage<T>;
2020
/* @ts-expect-error just a placeholder, will be implemented in subclass */
2121
protected _close(): Promise<void>;
22-
constructor(options?: BaseOptions<T>) {
22+
constructor(options?: O) {
2323
super();
2424

2525
if (options?.initMethod) {
@@ -44,7 +44,7 @@ export abstract class Base<T = any> extends ReadyEventEmitter {
4444
});
4545
});
4646
}
47-
this.options = options ?? {};
47+
this.options = options ?? ({} as O);
4848
this.#localStorage = this.options.localStorage ?? getAsyncLocalStorage<T>();
4949
super.on('error', err => {
5050
this._defaultErrorHandler(err);

0 commit comments

Comments
 (0)