本題
題名の通り、discord.js の TypeScript ビルド (トランスパイル) 時に typings/index.d.ts 周りのエラーが大量に発生するようになってしまった問題の解決方法を記載します。
解決方法
結論から言うと、TypeScript のバージョンを少なくとも 5.1.3 にアップデートすれば良いようです。
自分は 5.3.3 でエラーの解消を確認しました。
エラー内容
> npx tsc --build
node_modules/discord.js/typings/index.d.ts:1210:21 - error TS1139: Type parameter declaration expected.
1210 public getChannel<const Type extends ChannelType = ChannelType>(
~~~~~
node_modules/discord.js/typings/index.d.ts:1210:27 - error TS1435: Unknown keyword or identifier. Did you mean 'type'?
1210 public getChannel<const Type extends ChannelType = ChannelType>(
~~~~
node_modules/discord.js/typings/index.d.ts:1210:32 - error TS1068: Unexpected token. A constructor, method, accessor, or property was expected.
1210 public getChannel<const Type extends ChannelType = ChannelType>(
~~~~~~~
node_modules/discord.js/typings/index.d.ts:1211:9 - error TS1005: ')' expected.
1211 name: string,
~
node_modules/discord.js/typings/index.d.ts:1211:11 - error TS1068: Unexpected token. A constructor, method, accessor, or property was expected.
1211 name: string,
~~~~~~
node_modules/discord.js/typings/index.d.ts:1212:13 - error TS1005: ';' expected.
// 以下、同じような内容のエラーが続く。