chore: little type trick in pizzax.ts (#14891)

Make `makeGetterSetter` take the correct type associated with getter and setter
This commit is contained in:
Linca 2024-11-06 21:01:58 +08:00 committed by GitHub
parent b1c82213a3
commit f1eb17f66c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 8 additions and 4 deletions

View File

@ -241,9 +241,13 @@ export class Storage<T extends StateDef> {
* getter/setterを作ります * getter/setterを作ります
* vue上で設定コントロールのmodelとして使う用 * vue上で設定コントロールのmodelとして使う用
*/ */
public makeGetterSetter<K extends keyof T>(key: K, getter?: (v: T[K]) => unknown, setter?: (v: unknown) => T[K]): { public makeGetterSetter<K extends keyof T, R = T[K]['default']>(
get: () => T[K]['default']; key: K,
set: (value: T[K]['default']) => void; getter?: (v: T[K]['default']) => R,
setter?: (v: R) => T[K]['default'],
): {
get: () => R;
set: (value: R) => void;
} { } {
const valueRef = ref(this.state[key]); const valueRef = ref(this.state[key]);
@ -265,7 +269,7 @@ export class Storage<T extends StateDef> {
return valueRef.value; return valueRef.value;
} }
}, },
set: (value: unknown) => { set: (value) => {
const val = setter ? setter(value) : value; const val = setter ? setter(value) : value;
this.set(key, val); this.set(key, val);
valueRef.value = val; valueRef.value = val;