From bb3d274db64fe662ad01780ca5eadbc263f6f759 Mon Sep 17 00:00:00 2001 From: Kagami Sascha Rosylight Date: Sun, 18 Dec 2022 13:13:05 +0900 Subject: refactor(client): add proper types to `never[]` (#9340) --- packages/client/src/store.ts | 41 +++++++++++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 6 deletions(-) (limited to 'packages/client/src/store.ts') diff --git a/packages/client/src/store.ts b/packages/client/src/store.ts index 3971214af0..061e1913d6 100644 --- a/packages/client/src/store.ts +++ b/packages/client/src/store.ts @@ -2,11 +2,34 @@ import { markRaw, ref } from 'vue'; import { Storage } from './pizzax'; import { Theme } from './scripts/theme'; -export const postFormActions = []; -export const userActions = []; -export const noteActions = []; -export const noteViewInterruptors = []; -export const notePostInterruptors = []; +interface PostFormAction { + title: string, + handler: (form: T, update: (key: unknown, value: unknown) => void) => void; +} + +interface UserAction { + title: string, + handler: (user: UserDetailed) => void; +} + +interface NoteAction { + title: string, + handler: (note: Note) => void; +} + +interface NoteViewInterruptor { + handler: (note: Note) => unknown; +} + +interface NotePostInterruptor { + handler: (note: FIXME) => unknown; +} + +export const postFormActions: PostFormAction[] = []; +export const userActions: UserAction[] = []; +export const noteActions: NoteAction[] = []; +export const noteViewInterruptors: NoteViewInterruptor[] = []; +export const notePostInterruptors: NotePostInterruptor[] = []; // TODO: それぞれいちいちwhereとかdefaultというキーを付けなきゃいけないの冗長なのでなんとかする(ただ型定義が面倒になりそう) // あと、現行の定義の仕方なら「whereが何であるかに関わらずキー名の重複不可」という制約を付けられるメリットもあるからそのメリットを引き継ぐ方法も考えないといけない @@ -266,11 +289,17 @@ type Plugin = { ast: any[]; }; +interface Watcher { + key: string; + callback: (value: unknown) => void; +} + /** * 常にメモリにロードしておく必要がないような設定情報を保管するストレージ(非リアクティブ) */ import lightTheme from '@/themes/l-light.json5'; import darkTheme from '@/themes/d-green-lime.json5'; +import { Note, UserDetailed } from 'misskey-js/built/entities'; export class ColdDeviceStorage { public static default = { @@ -289,7 +318,7 @@ export class ColdDeviceStorage { sound_channel: { type: 'syuilo/square-pico', volume: 1 }, }; - public static watchers = []; + public static watchers: Watcher[] = []; public static get(key: T): typeof ColdDeviceStorage.default[T] { // TODO: indexedDBにする -- cgit v1.2.3-freya