discordjs / discord.js

A powerful JavaScript library for interacting with the Discord API
https://discord.js.org
Apache License 2.0
25.37k stars 3.97k forks source link

Unable to compile typescript due to typing problems #7110

Closed richbai90 closed 2 years ago

richbai90 commented 2 years ago

Issue description

I just updated my bot to version 13 and made all of the necesary changes to make it compatible, but I'm unable to compile the typescript due to typing errors. Every time I try I get these errors:

node_modules/discord.js/typings/index.d.ts:2989:41 - error TS1005: ';' expected.

2989 export type Constructable<T> = abstract new (...args: any[]) => T;
                                             ~~~

node_modules/discord.js/typings/index.d.ts:2989:46 - error TS1109: Expression expected.

2989 export type Constructable<T> = abstract new (...args: any[]) => T;
                                                  ~~~

node_modules/discord.js/typings/index.d.ts:2989:59 - error TS1011: An element access expression should take an argument.

2989 export type Constructable<T> = abstract new (...args: any[]) => T;

node_modules/discord.js/typings/index.d.ts:2989:60 - error TS1005: ';' expected.

2989 export type Constructable<T> = abstract new (...args: any[]) => T;
                                                                ~

node_modules/discord.js/typings/index.d.ts:2989:62 - error TS1128: Declaration or statement expected.

2989 export type Constructable<T> = abstract new (...args: any[]) => T;
                                                                  ~~

Found 5 errors.

tsconfig.json

{
  "compilerOptions": {
    "moduleResolution": "node",
    "target": "es5",
    "module": "commonjs",
    "lib": ["ES2015", "ES2016", "ES2017", "ES2018", "ES2019", "ES2020"],
    "strict": false,
    "sourceMap": true,
    "declaration": true,
    "allowSyntheticDefaultImports": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "esModuleInterop": true,
    "declarationDir": "dist/types",
    "outDir": "dist/lib",
    "typeRoots": ["node_modules/@types", "src/types"],
    "skipLibCheck": true,
  },
  "include": ["src"],
}

Code sample

import { assert } from 'console';
import { Client, Intents } from 'discord.js';
import 'core-js';

const bots: Map<symbol, Client> = new Map<symbol, Client>();
const TAKey = Symbol('TA');
const HelperKey = Symbol('HELPER');
const ta = connect(TAKey, bots);
const helper = connect(HelperKey, bots);
assert(ta && helper);

function connect (key: symbol, cache: Map<symbol, Client>) {
  if (!key.description) return;
  const bot = new Client({
    intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILD_MESSAGE_REACTIONS],
  });
  const token = process.env[key.description!];
  bot.login(token);
  cache.set(key, bot);
  return bot;
}

discord.js version

13.3.1

Node.js version

16.11.0

Operating system

macOS

Priority this issue should have

Medium (should be fixed soon)

Which partials do you have configured?

No Partials

Which gateway intents are you subscribing to?

GUILDS, GUILD_MEMBERS, GUILD_MESSAGE_REACTIONS

I have tested this issue on a development release

2ce244b

ImRodry commented 2 years ago

image Seems like you missed this, but please include the TS version

vladfrangu commented 2 years ago

Can also right off the bat mention that your TS version is most likely outdated

richbai90 commented 2 years ago

Yeah it was the TS version. I was on 4.1, updating to 4.5 fixed it. Sorry to waste your time, but I appreciate the help

ImRodry commented 2 years ago

This can be closed then @richbai90

skybird23333 commented 2 years ago

I also have the same issue, and I am using node v16.9.1 and typescript 4.5. I get the exact same errors as above.

imranbarbhuiya commented 2 years ago

I also have the same issue, and I am using node v16.9.1 and typescript 4.5. I get the exact same errors as above.

This issue is closed, please create a new issue with a minimal repro.