diff --git a/packages/client/src/pizzax.ts b/packages/client/src/pizzax.ts index 6974df94dc..b5c07714d4 100644 --- a/packages/client/src/pizzax.ts +++ b/packages/client/src/pizzax.ts @@ -5,12 +5,13 @@ import { onUnmounted, ref, watch } from "vue"; import { api } from "./os"; import { useStream } from "./stream"; import { isSignedIn, me } from "@/me"; +import type { TypeUtils } from "firefish-js"; type StateDef = Record< string, { where: "account" | "device" | "deviceAccount"; - default: any; + default: unknown; } >; @@ -82,8 +83,8 @@ export class Storage { for (const [k, v] of Object.entries(state)) { reactiveState[k] = ref(v); } - this.state = state as any; - this.reactiveState = reactiveState as any; + this.state = state as typeof this.state; + this.reactiveState = reactiveState as typeof this.reactiveState; if (isSignedIn) { // なぜかsetTimeoutしないとapi関数内でエラーになる(おそらく循環参照してることに原因がありそう) @@ -201,11 +202,11 @@ export class Storage { } } - public push( + public push>( key: K, value: ArrayElement, ): void { - const currentState = this.state[key]; + const currentState = this.state[key] as unknown[]; this.set(key, [...currentState, value]); } @@ -219,10 +220,10 @@ export class Storage { */ public makeGetterSetter( key: K, - getter?: (v: T[K]) => unknown, - setter?: (v: unknown) => T[K], + getter?: (oldV: T[K]["default"]) => T[K]["default"], + setter?: (oldV: T[K]["default"]) => T[K]["default"], ) { - const valueRef = ref(this.state[key]); + const valueRef = ref(this.state[key]) as Ref; const stop = watch(this.reactiveState[key], (val) => { valueRef.value = val; @@ -242,7 +243,7 @@ export class Storage { return valueRef.value; } }, - set: (value: unknown) => { + set: (value: T[K]["default"]) => { const val = setter ? setter(value) : value; this.set(key, val); valueRef.value = val; diff --git a/packages/firefish-js/src/type-utils.ts b/packages/firefish-js/src/type-utils.ts index bf8297487b..bb2d843f45 100644 --- a/packages/firefish-js/src/type-utils.ts +++ b/packages/firefish-js/src/type-utils.ts @@ -1,6 +1,6 @@ import type { Endpoints } from "./api.types"; -type PropertyOfType = { +export type PropertyOfType = { [K in keyof Type]: Type[K] extends U ? K : never; }[keyof Type];