mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 08:03:30 +01:00
types(core): use result types instead of direct types (#11140)
* types(core): use result types instead of direct types fix: import pains chore: apply suggestion from review Co-authored-by: Almeida <github@almeidx.dev> chore: fmt script chore: requested change * chore: rename script, fix build * chore: types --------- Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
@@ -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<string>();
|
||||
|
||||
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]!);
|
||||
}
|
||||
}
|
||||
|
||||
28
packages/core/scripts/find-returns-not-return-type.mts
Normal file
28
packages/core/scripts/find-returns-not-return-type.mts
Normal file
@@ -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<(?<returnType>\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');
|
||||
}
|
||||
@@ -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<APIThreadChannel>;
|
||||
}) as Promise<RESTPostAPIChannelThreadsResult>;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user