refactor8frontend9: anyを除去 (#16778)

This commit is contained in:
かっこかり 2025-11-10 15:33:54 +09:00 committed by GitHub
parent 73bcd330f7
commit fd2fe34270
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
16 changed files with 42 additions and 110 deletions

View File

@ -13,17 +13,16 @@ SPDX-License-Identifier: AGPL-3.0-only
</MkPagination> </MkPagination>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup generic="P extends IPaginator">
import * as Misskey from 'misskey-js'; import * as Misskey from 'misskey-js';
import type { IPaginator } from '@/utility/paginator.js'; import type { IPaginator, ExtractorFunction } from '@/utility/paginator.js';
import MkChannelPreview from '@/components/MkChannelPreview.vue'; import MkChannelPreview from '@/components/MkChannelPreview.vue';
import MkPagination from '@/components/MkPagination.vue'; import MkPagination from '@/components/MkPagination.vue';
import { i18n } from '@/i18n.js';
const props = withDefaults(defineProps<{ const props = withDefaults(defineProps<{
paginator: IPaginator; paginator: P;
noGap?: boolean; noGap?: boolean;
extractor?: (item: any) => Misskey.entities.Channel; extractor?: ExtractorFunction<P, Misskey.entities.Channel>;
}>(), { }>(), {
extractor: (item) => item, extractor: (item) => item,
}); });

View File

@ -15,17 +15,17 @@ SPDX-License-Identifier: AGPL-3.0-only
</MkPagination> </MkPagination>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup generic="P extends IPaginator">
import * as Misskey from 'misskey-js'; import * as Misskey from 'misskey-js';
import type { IPaginator } from '@/utility/paginator.js'; import type { IPaginator, ExtractorFunction } from '@/utility/paginator.js';
import MkUserInfo from '@/components/MkUserInfo.vue'; import MkUserInfo from '@/components/MkUserInfo.vue';
import MkPagination from '@/components/MkPagination.vue'; import MkPagination from '@/components/MkPagination.vue';
import { i18n } from '@/i18n.js'; import { i18n } from '@/i18n.js';
const props = withDefaults(defineProps<{ const props = withDefaults(defineProps<{
paginator: IPaginator; paginator: P;
noGap?: boolean; noGap?: boolean;
extractor?: (item: any) => Misskey.entities.UserDetailed; extractor?: ExtractorFunction<P, Misskey.entities.UserDetailed>;
}>(), { }>(), {
extractor: (item) => item, extractor: (item) => item,
}); });

View File

@ -19,10 +19,13 @@ export function useForm<T extends Record<string, any>>(initialState: T, save: (n
const currentState = reactive<T>(copy(initialState)); const currentState = reactive<T>(copy(initialState));
const previousState = reactive<T>(copy(initialState)); const previousState = reactive<T>(copy(initialState));
const modifiedStates = reactive<Record<keyof T, boolean>>({} as any); const modifiedStates = reactive<Record<keyof T, boolean>>((() => {
for (const key in currentState) { const obj: Record<keyof T, boolean> = {} as Record<keyof T, boolean>;
modifiedStates[key] = false; for (const key in initialState) {
obj[key] = false;
} }
return obj;
})());
const modified = computed(() => Object.values(modifiedStates).some(v => v)); const modified = computed(() => Object.values(modifiedStates).some(v => v));
const modifiedCount = computed(() => Object.values(modifiedStates).filter(v => v).length); const modifiedCount = computed(() => Object.values(modifiedStates).filter(v => v).length);

View File

@ -4,13 +4,14 @@
*/ */
import type { InjectionKey, Ref } from 'vue'; import type { InjectionKey, Ref } from 'vue';
import type { PageMetadata } from '@/page.js';
import type { Router } from '@/router.js'; import type { Router } from '@/router.js';
export const DI = { export const DI = {
routerCurrentDepth: Symbol() as InjectionKey<number>, routerCurrentDepth: Symbol() as InjectionKey<number>,
router: Symbol() as InjectionKey<Router>, router: Symbol() as InjectionKey<Router>,
mock: Symbol() as InjectionKey<boolean>, mock: Symbol() as InjectionKey<boolean>,
pageMetadata: Symbol() as InjectionKey<Ref<Record<string, any> | null>>, pageMetadata: Symbol() as InjectionKey<Ref<PageMetadata | null>>,
viewId: Symbol() as InjectionKey<string>, viewId: Symbol() as InjectionKey<string>,
currentStickyTop: Symbol() as InjectionKey<Ref<number>>, currentStickyTop: Symbol() as InjectionKey<Ref<number>>,
currentStickyBottom: Symbol() as InjectionKey<Ref<number>>, currentStickyBottom: Symbol() as InjectionKey<Ref<number>>,

View File

@ -7,7 +7,7 @@ import type { Directive } from 'vue';
import { getBgColor } from '@/utility/get-bg-color.js'; import { getBgColor } from '@/utility/get-bg-color.js';
import { globalEvents } from '@/events.js'; import { globalEvents } from '@/events.js';
const handlerMap = new WeakMap<any, any>(); const handlerMap = new WeakMap<HTMLElement, () => void>();
export const adaptiveBorderDirective = { export const adaptiveBorderDirective = {
mounted(src) { mounted(src) {

View File

@ -119,9 +119,9 @@ export const userPreviewDirective = {
// TODO: 新たにプロパティを作るのをやめMapを使う // TODO: 新たにプロパティを作るのをやめMapを使う
// ただメモリ的には↓の方が省メモリかもしれないので検討中 // ただメモリ的には↓の方が省メモリかもしれないので検討中
const self = (el as any)._userPreviewDirective_ = {} as any; el._userPreviewDirective_ = {
preview: new UserPreview(el, binding.value),
self.preview = new UserPreview(el, binding.value); };
}, },
unmounted(el, binding) { unmounted(el, binding) {

View File

@ -59,7 +59,7 @@ export class Pizzax<T extends StateDef> {
private pizzaxChannel: BroadcastChannel<PizzaxChannelMessage<T>>; private pizzaxChannel: BroadcastChannel<PizzaxChannelMessage<T>>;
// 簡易的にキューイングして占有ロックとする // 簡易的にキューイングして占有ロックとする
private currentIdbJob: Promise<any> = Promise.resolve(); private currentIdbJob: Promise<unknown> = Promise.resolve();
private addIdbSetJob<T>(job: () => Promise<T>) { private addIdbSetJob<T>(job: () => Promise<T>) {
const promise = this.currentIdbJob.then(job, err => { const promise = this.currentIdbJob.then(job, err => {
console.error('Pizzax failed to save data to idb!', err); console.error('Pizzax failed to save data to idb!', err);

View File

@ -257,7 +257,7 @@ const {
const user = ref(result.user); const user = ref(result.user);
const info = ref(result.info); const info = ref(result.info);
const ips = ref(result.ips); const ips = ref(result.ips);
const ap = ref<any>(null); const ap = ref<Misskey.entities.ApGetResponse | null>(null);
const moderator = ref(info.value.isModerator); const moderator = ref(info.value.isModerator);
const silenced = ref(info.value.isSilenced); const silenced = ref(info.value.isSilenced);
const suspended = ref(info.value.isSuspended); const suspended = ref(info.value.isSuspended);

View File

@ -44,7 +44,7 @@ async function addRelay() {
if (canceled || inbox == null) return; if (canceled || inbox == null) return;
misskeyApi('admin/relays/add', { misskeyApi('admin/relays/add', {
inbox, inbox,
}).then((relay: any) => { }).then(() => {
refresh(); refresh();
}).catch((err: any) => { }).catch((err: any) => {
os.alert({ os.alert({

View File

@ -161,7 +161,11 @@ async function _fetch_() {
}, },
raw: res.data, raw: res.data,
}; };
} catch (err: any) { } catch (err) {
if (!(err instanceof Error)) {
throw err;
}
switch (err.message.toLowerCase()) { switch (err.message.toLowerCase()) {
case 'this theme is already installed': case 'this theme is already installed':
errorKV.value = { errorKV.value = {

View File

@ -7,8 +7,6 @@ import * as Misskey from 'misskey-js';
import { markRaw } from 'vue'; import { markRaw } from 'vue';
import { $i } from '@/i.js'; import { $i } from '@/i.js';
import { wsOrigin } from '@@/js/config.js'; import { wsOrigin } from '@@/js/config.js';
// TODO: No WebsocketモードでStreamMockが使えそう
//import { StreamMock } from '@/utility/stream-mock.js';
// heart beat interval in ms // heart beat interval in ms
const HEART_BEAT_INTERVAL = 1000 * 60; const HEART_BEAT_INTERVAL = 1000 * 60;

View File

@ -124,7 +124,7 @@ export function uploadFile(file: File | Blob, options: {
const driveFile = JSON.parse(ev.target.response); const driveFile = JSON.parse(ev.target.response);
globalEvents.emit('driveFileCreated', driveFile); globalEvents.emit('driveFileCreated', driveFile);
resolve(driveFile); resolve(driveFile);
}) as (ev: ProgressEvent<EventTarget>) => any; }) as (ev: ProgressEvent<EventTarget>) => void;
if (options.onProgress) { if (options.onProgress) {
xhr.upload.onprogress = ev => { xhr.upload.onprogress = ev => {

View File

@ -13,7 +13,7 @@ interface CommonParamDef {
type: string; type: string;
label?: string; label?: string;
caption?: string; caption?: string;
default: any; default: unknown;
} }
interface NumberParamDef extends CommonParamDef { interface NumberParamDef extends CommonParamDef {

View File

@ -5,7 +5,7 @@
import { ref, shallowRef, triggerRef } from 'vue'; import { ref, shallowRef, triggerRef } from 'vue';
import * as Misskey from 'misskey-js'; import * as Misskey from 'misskey-js';
import type { ComputedRef, Ref, ShallowRef } from 'vue'; import type { ComputedRef, Ref, ShallowRef, UnwrapRef } from 'vue';
import { misskeyApi } from '@/utility/misskey-api.js'; import { misskeyApi } from '@/utility/misskey-api.js';
const MAX_ITEMS = 30; const MAX_ITEMS = 30;
@ -19,7 +19,12 @@ export type MisskeyEntity = {
_shouldInsertAd_?: boolean; _shouldInsertAd_?: boolean;
}; };
type FilterByEpRes<E extends Record<string, any>> = { type AbsEndpointType = {
req: unknown;
res: unknown;
};
type FilterByEpRes<E extends Record<string, AbsEndpointType>> = {
[K in keyof E]: E[K]['res'] extends Array<{ id: string }> ? K : never [K in keyof E]: E[K]['res'] extends Array<{ id: string }> ? K : never
}[keyof E]; }[keyof E];
export type PaginatorCompatibleEndpointPaths = FilterByEpRes<Misskey.Endpoints>; export type PaginatorCompatibleEndpointPaths = FilterByEpRes<Misskey.Endpoints>;
@ -27,6 +32,8 @@ export type PaginatorCompatibleEndpoints = {
[K in PaginatorCompatibleEndpointPaths]: Misskey.Endpoints[K]; [K in PaginatorCompatibleEndpointPaths]: Misskey.Endpoints[K];
}; };
export type ExtractorFunction<P extends IPaginator, T> = (item: UnwrapRef<P['items']>[number]) => T;
export interface IPaginator<T = unknown, _T = T & MisskeyEntity> { export interface IPaginator<T = unknown, _T = T & MisskeyEntity> {
/** /**
* *

View File

@ -1,81 +0,0 @@
/*
* SPDX-FileCopyrightText: syuilo and misskey-project
* SPDX-License-Identifier: AGPL-3.0-only
*/
import { EventEmitter } from 'eventemitter3';
import * as Misskey from 'misskey-js';
import type { Channels, StreamEvents, IStream, IChannelConnection } from 'misskey-js';
type AnyOf<T extends Record<any, any>> = T[keyof T];
type OmitFirst<T extends any[]> = T extends [any, ...infer R] ? R : never;
/**
* Websocket無効化時に使うStreamのモック
*/
export class StreamMock extends EventEmitter<StreamEvents> implements IStream {
public readonly state = 'initializing';
constructor(...args: ConstructorParameters<typeof Misskey.Stream>) {
super();
// do nothing
}
public useChannel<C extends keyof Channels>(channel: C, params?: Channels[C]['params'], name?: string): ChannelConnectionMock<Channels[C]> {
return new ChannelConnectionMock(this, channel, name);
}
public removeSharedConnection(connection: any): void {
// do nothing
}
public removeSharedConnectionPool(pool: any): void {
// do nothing
}
public disconnectToChannel(): void {
// do nothing
}
public send(typeOrPayload: string): void;
public send(typeOrPayload: string, payload: any): void;
public send(typeOrPayload: Record<string, any> | any[]): void;
public send(typeOrPayload: string | Record<string, any> | any[], payload?: any): void {
// do nothing
}
public ping(): void {
// do nothing
}
public heartbeat(): void {
// do nothing
}
public close(): void {
// do nothing
}
}
class ChannelConnectionMock<Channel extends AnyOf<Channels> = any> extends EventEmitter<Channel['events']> implements IChannelConnection<Channel> {
public id = '';
public name?: string; // for debug
public inCount = 0; // for debug
public outCount = 0; // for debug
public channel: string;
constructor(stream: IStream, ...args: OmitFirst<ConstructorParameters<typeof Misskey.ChannelConnection<Channel>>>) {
super();
this.channel = args[0];
this.name = args[1];
}
public send<T extends keyof Channel['receives']>(type: T, body: Channel['receives'][T]): void {
// do nothing
}
public dispose(): void {
// do nothing
}
}

View File

@ -222,7 +222,8 @@ export class WatermarkRenderer {
}, },
}); });
} else { } else {
throw new Error(`Unrecognized layer type: ${(layer as any).type}`); // @ts-expect-error Should be unreachable
throw new Error(`Unrecognized layer type: ${layer.type}`);
} }
} }