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

View file

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