From 1fcc735f1b1eae7532a97087e19ec3707478f02a Mon Sep 17 00:00:00 2001 From: Vlad Frangu Date: Sun, 5 Oct 2025 15:17:01 +0300 Subject: [PATCH 1/3] types(core): use result types instead of direct types fix: import pains chore: apply suggestion from review Co-authored-by: Almeida chore: fmt script chore: requested change --- .../scripts/find-returns-not-return-type.mts | 28 +++++++++++++++++++ packages/core/src/api/channel.ts | 4 +-- 2 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 packages/core/scripts/find-returns-not-return-type.mts diff --git a/packages/core/scripts/find-returns-not-return-type.mts b/packages/core/scripts/find-returns-not-return-type.mts new file mode 100644 index 000000000000..71e11042b175 --- /dev/null +++ b/packages/core/scripts/find-returns-not-return-type.mts @@ -0,0 +1,28 @@ +import { glob, readFile } from 'node:fs/promises'; + +const cwd = new URL('../src/api/', import.meta.url); +const results: string[] = []; + +for await (const file of glob('**/*.ts', { cwd })) { + const content = await readFile(new URL(file, cwd), { encoding: 'utf-8' }); + + const matches = content.matchAll(/as Promise<(?\w+)>/g); + + for (const match of matches) { + const returnType = match.groups!.returnType!; + + if (!returnType.startsWith('REST') || !returnType.includes('Result')) { + results.push(`in file core/src/api/${file}: ${returnType}`); + } + } +} + +if (results.length > 0) { + console.warn('Found return types that are not REST return types:'); + + for (const result of results) { + console.warn(` - ${result}`); + } +} else { + console.log('No return types that are not REST return types found'); +} diff --git a/packages/core/src/api/channel.ts b/packages/core/src/api/channel.ts index 89f38d9403d8..b4157fb1b00f 100644 --- a/packages/core/src/api/channel.ts +++ b/packages/core/src/api/channel.ts @@ -29,8 +29,6 @@ import { type RESTPostAPIChannelMessageResult, type RESTPostAPIChannelThreadsJSONBody, type RESTPostAPIChannelThreadsResult, - type RESTPostAPIChannelWebhookJSONBody, - type RESTPostAPIChannelWebhookResult, type RESTPostAPIGuildForumThreadsJSONBody, type RESTPostAPISendSoundboardSoundResult, type RESTPostAPISoundboardSendSoundJSONBody, @@ -566,7 +564,7 @@ export class ChannelsAPI { body, reason, signal, - }) as Promise; + }) as Promise; } /** From f0af5bf650acc8414753eb58316a56f4391ca1e3 Mon Sep 17 00:00:00 2001 From: Vlad Frangu Date: Wed, 8 Oct 2025 12:06:52 +0300 Subject: [PATCH 2/3] chore: rename script, fix build --- .../core/scripts/{check-routes.mjs => check-routes.mts} | 6 ++++-- packages/core/src/api/channel.ts | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) rename packages/core/scripts/{check-routes.mjs => check-routes.mts} (81%) diff --git a/packages/core/scripts/check-routes.mjs b/packages/core/scripts/check-routes.mts similarity index 81% rename from packages/core/scripts/check-routes.mjs rename to packages/core/scripts/check-routes.mts index 1cb08866ba7a..e0c14421ac83 100644 --- a/packages/core/scripts/check-routes.mjs +++ b/packages/core/scripts/check-routes.mts @@ -13,8 +13,10 @@ const ignoredRoutes = new Set([ 'nitroStickerPacks', ]); -for await (const file of glob('src/api/*.ts')) { - const content = await readFile(file, 'utf-8'); +const cwd = new URL('../src/api/', import.meta.url); + +for await (const file of glob('**/*.ts', { cwd })) { + const content = await readFile(new URL(file, cwd), 'utf-8'); const routes = content.matchAll(/Routes\.([\w\d_]+)/g); for (const route of routes) { diff --git a/packages/core/src/api/channel.ts b/packages/core/src/api/channel.ts index b4157fb1b00f..ca062a70e860 100644 --- a/packages/core/src/api/channel.ts +++ b/packages/core/src/api/channel.ts @@ -3,7 +3,6 @@ import { makeURLSearchParams, type RawFile, type RequestData, type REST } from '@discordjs/rest'; import { Routes, - type APIThreadChannel, type RESTDeleteAPIChannelResult, type RESTGetAPIChannelInvitesResult, type RESTGetAPIChannelMessageReactionUsersQuery, @@ -29,6 +28,8 @@ import { type RESTPostAPIChannelMessageResult, type RESTPostAPIChannelThreadsJSONBody, type RESTPostAPIChannelThreadsResult, + type RESTPostAPIChannelWebhookJSONBody, + type RESTPostAPIChannelWebhookResult, type RESTPostAPIGuildForumThreadsJSONBody, type RESTPostAPISendSoundboardSoundResult, type RESTPostAPISoundboardSendSoundJSONBody, From 35d704f3199c0f87a4cd4a8217ea876e2faf962b Mon Sep 17 00:00:00 2001 From: Vlad Frangu Date: Wed, 8 Oct 2025 16:14:37 +0300 Subject: [PATCH 3/3] chore: types --- packages/core/scripts/check-routes.mts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/core/scripts/check-routes.mts b/packages/core/scripts/check-routes.mts index e0c14421ac83..b15899ed5ed8 100644 --- a/packages/core/scripts/check-routes.mts +++ b/packages/core/scripts/check-routes.mts @@ -1,7 +1,7 @@ import { Routes } from 'discord-api-types/v10'; import { glob, readFile } from 'node:fs/promises'; -const usedRoutes = new Set(); +const usedRoutes = new Set(); const ignoredRoutes = new Set([ // Deprecated @@ -20,7 +20,7 @@ for await (const file of glob('**/*.ts', { cwd })) { const routes = content.matchAll(/Routes\.([\w\d_]+)/g); for (const route of routes) { - usedRoutes.add(route[1]); + usedRoutes.add(route[1]!); } }