mirror of
https://github.com/misskey-dev/misskey.git
synced 2026-03-24 13:03:39 +00:00
chore(frontend): improve type def
This commit is contained in:
@@ -6,12 +6,12 @@
|
||||
import * as Misskey from 'misskey-js';
|
||||
import { hemisphere } from '@@/js/intl-const.js';
|
||||
import { v4 as uuid } from 'uuid';
|
||||
import { definePreferences } from './manager.js';
|
||||
import type { Theme } from '@/theme.js';
|
||||
import type { SoundType } from '@/utility/sound.js';
|
||||
import type { Plugin } from '@/plugin.js';
|
||||
import type { DeviceKind } from '@/utility/device-kind.js';
|
||||
import type { DeckProfile } from '@/deck.js';
|
||||
import type { PreferencesDefinition } from './manager.js';
|
||||
import { DEFAULT_DEVICE_KIND } from '@/utility/device-kind.js';
|
||||
import { deepEqual } from '@/utility/deep-equal.js';
|
||||
|
||||
@@ -33,7 +33,7 @@ export type SoundStore = {
|
||||
|
||||
// NOTE: デフォルト値は他の設定の状態に依存してはならない(依存していた場合、ユーザーがその設定項目単体で「初期値にリセット」した場合不具合の原因になる)
|
||||
|
||||
export const PREF_DEF = {
|
||||
export const PREF_DEF = definePreferences({
|
||||
accounts: {
|
||||
default: [] as [host: string, user: {
|
||||
id: string;
|
||||
@@ -88,7 +88,7 @@ export const PREF_DEF = {
|
||||
emojis: string[];
|
||||
}[],
|
||||
mergeStrategy: (a, b) => {
|
||||
const mergedItems = [] as (typeof a)[];
|
||||
const mergedItems = [] as typeof a;
|
||||
for (const x of a.concat(b)) {
|
||||
const sameIdItem = mergedItems.find(y => y.id === x.id);
|
||||
if (sameIdItem != null) {
|
||||
@@ -119,7 +119,7 @@ export const PREF_DEF = {
|
||||
themes: {
|
||||
default: [] as Theme[],
|
||||
mergeStrategy: (a, b) => {
|
||||
const mergedItems = [] as (typeof a)[];
|
||||
const mergedItems = [] as typeof a;
|
||||
for (const x of a.concat(b)) {
|
||||
const sameIdItem = mergedItems.find(y => y.id === x.id);
|
||||
if (sameIdItem != null) {
|
||||
@@ -464,4 +464,4 @@ export const PREF_DEF = {
|
||||
'experimental.enableFolderPageView': {
|
||||
default: false,
|
||||
},
|
||||
} satisfies PreferencesDefinition;
|
||||
});
|
||||
|
||||
@@ -96,6 +96,14 @@ type PreferencesDefinitionRecord<Default, T = Default extends (...args: any) =>
|
||||
|
||||
export type PreferencesDefinition = Record<string, PreferencesDefinitionRecord<any>>;
|
||||
|
||||
export function definePreferences<T extends Record<string, unknown>>(x: {
|
||||
[K in keyof T]: PreferencesDefinitionRecord<T[K]>
|
||||
}): {
|
||||
[K in keyof T]: PreferencesDefinitionRecord<T[K]>
|
||||
} {
|
||||
return x;
|
||||
}
|
||||
|
||||
export function getInitialPrefValue<K extends keyof PREF>(k: K): ValueOf<K> {
|
||||
if (typeof PREF_DEF[k].default === 'function') { // factory
|
||||
return PREF_DEF[k].default();
|
||||
|
||||
Reference in New Issue
Block a user