1
0
mirror of https://github.com/misskey-dev/misskey.git synced 2026-05-14 14:35:38 +02:00

refactor(frontend): フロントエンドの型エラー解消(途中まで) (#16539)

* fix(frontend): FormLinkをボタンとして使用した際にエラーが出る問題を修正

* refactor(frontend): フロントエンドの型エラー解消

* remove unused ts-expect-error

* migrate

* remove unrelated changes

* fix lint

* more type fixes
This commit is contained in:
かっこかり
2025-09-13 08:33:14 +09:00
committed by GitHub
parent c174c5c144
commit 5b4115e21a
56 changed files with 316 additions and 236 deletions

View File

@@ -7,7 +7,7 @@ import { ref } from 'vue';
import { compareVersions } from 'compare-versions';
import { isSafeMode } from '@@/js/config.js';
import * as Misskey from 'misskey-js';
import type { Parser, Interpreter, values } from '@syuilo/aiscript';
import type { Parser, Interpreter, values, utils as utils_TypeReferenceOnly } from '@syuilo/aiscript';
import type { FormWithDefault } from '@/utility/form.js';
import { genId } from '@/utility/id.js';
import { store } from '@/store.js';
@@ -82,22 +82,23 @@ export async function parsePluginMeta(code: string): Promise<AiScriptPluginMeta>
}
const metadata = meta.get(null);
if (metadata == null) {
throw new Error('Metadata not found');
if (metadata == null || typeof metadata !== 'object' || Array.isArray(metadata)) {
throw new Error('Metadata not found or invalid');
}
const { name, version, author, description, permissions, config } = metadata;
if (name == null || version == null || author == null) {
throw new Error('Required property not found');
}
return {
name,
version,
author,
description,
permissions,
config,
name: name as string,
version: version as string,
author: author as string,
description: description as string | undefined,
permissions: permissions as string[] | undefined,
config: config as Record<string, any> | undefined,
};
}
@@ -110,7 +111,7 @@ export async function authorizePlugin(plugin: Plugin) {
title: i18n.ts.tokenRequested,
information: i18n.ts.pluginTokenRequestedDescription,
initialName: plugin.name,
initialPermissions: plugin.permissions,
initialPermissions: plugin.permissions as typeof Misskey.permissions[number][],
}, {
done: async result => {
const { name, permissions } = result;
@@ -149,6 +150,7 @@ export async function installPlugin(code: string, meta?: AiScriptPluginMeta) {
const plugin = {
...realMeta,
config: realMeta.config ?? {},
installId,
active: true,
configData: {},
@@ -353,7 +355,9 @@ export function changePluginActive(plugin: Plugin, active: boolean) {
async function createPluginEnv(opts: { plugin: Plugin; storageKey: string }): Promise<Record<string, values.Value>> {
const id = opts.plugin.installId;
const { utils, values } = await import('@syuilo/aiscript');
const ais = await import('@syuilo/aiscript');
const values = ais.values;
const utils: typeof utils_TypeReferenceOnly = ais.utils;
const { createAiScriptEnv } = await import('@/aiscript/api.js');
const config = new Map<string, values.Value>();
@@ -375,7 +379,7 @@ async function createPluginEnv(opts: { plugin: Plugin; storageKey: string }): Pr
utils.assertFunction(handler);
addPluginHandler(id, 'post_form_action', {
title: title.value,
handler: withContext(ctx => (form, update) => {
handler: (form, update) => withContext(ctx => {
ctx.execFn(handler, [utils.jsToVal(form), values.FN_NATIVE(([key, value]) => {
if (!key || !value) {
return;
@@ -391,7 +395,7 @@ async function createPluginEnv(opts: { plugin: Plugin; storageKey: string }): Pr
utils.assertFunction(handler);
addPluginHandler(id, 'user_action', {
title: title.value,
handler: withContext(ctx => (user) => {
handler: (user) => withContext(ctx => {
ctx.execFn(handler, [utils.jsToVal(user)]);
}),
});
@@ -402,7 +406,7 @@ async function createPluginEnv(opts: { plugin: Plugin; storageKey: string }): Pr
utils.assertFunction(handler);
addPluginHandler(id, 'note_action', {
title: title.value,
handler: withContext(ctx => (note) => {
handler: (note) => withContext(ctx => {
ctx.execFn(handler, [utils.jsToVal(note)]);
}),
});
@@ -411,8 +415,8 @@ async function createPluginEnv(opts: { plugin: Plugin; storageKey: string }): Pr
'Plugin:register:note_view_interruptor': values.FN_NATIVE(([handler]) => {
utils.assertFunction(handler);
addPluginHandler(id, 'note_view_interruptor', {
handler: withContext(ctx => (note) => {
return utils.valToJs(ctx.execFnSync(handler, [utils.jsToVal(note)]));
handler: (note) => withContext(ctx => {
return utils.valToJs(ctx.execFnSync(handler, [utils.jsToVal(note)])) as Misskey.entities.Note | null;
}),
});
}),
@@ -420,8 +424,8 @@ async function createPluginEnv(opts: { plugin: Plugin; storageKey: string }): Pr
'Plugin:register:note_post_interruptor': values.FN_NATIVE(([handler]) => {
utils.assertFunction(handler);
addPluginHandler(id, 'note_post_interruptor', {
handler: withContext(ctx => async (note) => {
return utils.valToJs(await ctx.execFn(handler, [utils.jsToVal(note)]));
handler: (note) => withContext(ctx => {
return utils.valToJs(ctx.execFnSync(handler, [utils.jsToVal(note)]));
}),
});
}),
@@ -429,8 +433,8 @@ async function createPluginEnv(opts: { plugin: Plugin; storageKey: string }): Pr
'Plugin:register:page_view_interruptor': values.FN_NATIVE(([handler]) => {
utils.assertFunction(handler);
addPluginHandler(id, 'page_view_interruptor', {
handler: withContext(ctx => async (page) => {
return utils.valToJs(await ctx.execFn(handler, [utils.jsToVal(page)]));
handler: (page) => withContext(ctx => {
return utils.valToJs(ctx.execFnSync(handler, [utils.jsToVal(page)])) as Misskey.entities.Page;
}),
});
}),