chore: little type trick in pizzax.ts

Make `makeGetterSetter` take the correct type associated with getter and setter
This commit is contained in:
Linca 2024-11-05 21:01:03 +08:00 committed by GitHub
parent 6718a54f6f
commit 9d9cc19249
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を作ります
* 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;