diff --git a/packages/core/scripts/check-routes.mjs b/packages/core/scripts/check-routes.mts similarity index 74% rename from packages/core/scripts/check-routes.mjs rename to packages/core/scripts/check-routes.mts index 1cb08866ba7a..b15899ed5ed8 100644 --- a/packages/core/scripts/check-routes.mjs +++ 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 @@ -13,12 +13,14 @@ 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) { - usedRoutes.add(route[1]); + usedRoutes.add(route[1]!); } } 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..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, @@ -566,7 +565,7 @@ export class ChannelsAPI { body, reason, signal, - }) as Promise; + }) as Promise; } /**