mirror of
https://activitypub.software/TransFem-org/Sharkey
synced 2024-11-28 08:53:02 +00:00
chore: little type trick in pizzax.ts (#14891)
Make `makeGetterSetter` take the correct type associated with getter and setter
This commit is contained in:
parent
b1c82213a3
commit
f1eb17f66c
1 changed files with 8 additions and 4 deletions
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue