Skip to content

Commit

Permalink
chore: little type trick in pizzax.ts (#14891)
Browse files Browse the repository at this point in the history
Make `makeGetterSetter` take the correct type associated with getter and setter
  • Loading branch information
Lhcfl authored Nov 6, 2024
1 parent b1c8221 commit f1eb17f
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions packages/frontend/src/pizzax.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]);

Expand All @@ -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;
Expand Down

0 comments on commit f1eb17f

Please sign in to comment.