Discord.js: Few typing issues

Created on 18 Sep 2018  Â·  2Comments  Â·  Source: discordjs/discord.js

Please describe the problem you are having in as much detail as possible:
tsc reports errors with the typings file

Include a reproducible code sample here, if possible:

import { Client } from 'discord.js';

new Client()
    .on('ready', () => console.log('Ready'))
    .login(process.env.TOKEN);

Further details:

  • discord.js version: d2da771e0f28773587766ede94cfdae222deefa0
  • Node.js version: 10.10.0
  • Operating system: Windows 10 Pro x64 1803
  • Priority this issue should have – please be realistic and elaborate if possible: Minor

  • [ ] I found this issue while running code on a __user account__
  • [x] I have also tested the issue on latest master, commit hash: d2da771e0f28773587766ede94cfdae222deefa0

Extension of #2835 but not locked, with more input
Here's a video I made to help show it, though it's just showing the same errors as below:
https://youtu.be/GvgDsJeEB8I

tsc output:

node_modules/discord.js/typings/index.d.ts:38:15 - error TS2417: Class static side 'typeof ActivityFlags' incorrectly extends base class static side 'typeof BitField'.
  Types of property 'resolve' are incompatible.
    Type '(permission: BitFieldResolvable<ActivityFlagsString>) => number' is not assignable to type '(bit?: string | number | Readonly<BitField<string>> | RecursiveArray<string | number | Readonly<BitField<string>>> | undefined) => number'.
      Types of parameters 'permission' and 'bit' are incompatible.
        Type 'string | number | Readonly<BitField<string>> | RecursiveArray<string | number | Readonly<BitField<string>>> | undefined' is not assignable to type 'BitFieldResolvable<ActivityFlagsString>'.
          Type 'undefined' is not assignable to type 'BitFieldResolvable<ActivityFlagsString>'.

38  export class ActivityFlags extends BitField<ActivityFlagsString> {
                 ~~~~~~~~~~~~~

node_modules/discord.js/typings/index.d.ts:789:15 - error TS2417: Class static side 'typeof Permissions' incorrectly extends base class static side 'typeof BitField'.
  Types of property 'resolve' are incompatible.
    Type '(permission?: number | "CREATE_INSTANT_INVITE" | "KICK_MEMBERS" | "BAN_MEMBERS" | "ADMINISTRATOR" | "MANAGE_CHANNELS" | "MANAGE_GUILD" | "ADD_REACTIONS" | "VIEW_AUDIT_LOG" | "PRIORITY_SPEAKER" | ... 22 more ... | undefined) =>
number' is not assignable to type '(bit?: string | number | Readonly<BitField<string>> | RecursiveArray<string | number | Readonly<BitField<string>>> | undefined) => number'.
      Types of parameters 'permission' and 'bit' are incompatible.
        Type 'string | number | Readonly<BitField<string>> | RecursiveArray<string | number | Readonly<BitField<string>>> | undefined' is not assignable to type 'number | "CREATE_INSTANT_INVITE" | "KICK_MEMBERS" | "BAN_MEMBERS" | "ADMINISTRATOR" | "MANAGE_CHANNELS" | "MANAGE_GUILD" | "ADD_REACTIONS" | "VIEW_AUDIT_LOG" | "PRIORITY_SPEAKER" | ... 22 more ... | undefined'.
          Type 'string' is not assignable to type 'number | "CREATE_INSTANT_INVITE" | "KICK_MEMBERS" | "BAN_MEMBERS" | "ADMINISTRATOR" | "MANAGE_CHANNELS" | "MANAGE_GUILD" | "ADD_REACTIONS" | "VIEW_AUDIT_LOG" | "PRIORITY_SPEAKER" | ... 22 more ... | undefined'.

789  export class Permissions extends BitField<PermissionString> {
                  ~~~~~~~~~~~

node_modules/discord.js/typings/index.d.ts:1018:15 - error TS2417: Class static side 'typeof Speaking' incorrectly extends base class static side 'typeof BitField'.
  Types of property 'resolve' are incompatible.
    Type '(permission: BitFieldResolvable<SpeakingString>) => number' is not assignable to type '(bit?: string | number | Readonly<BitField<string>> | RecursiveArray<string | number | Readonly<BitField<string>>> | undefined) => number'.
      Types of parameters 'permission' and 'bit' are incompatible.
        Type 'string | number | Readonly<BitField<string>> | RecursiveArray<string | number | Readonly<BitField<string>>> | undefined' is not assignable to type 'BitFieldResolvable<SpeakingString>'.
          Type 'undefined' is not assignable to type 'BitFieldResolvable<SpeakingString>'.

1018  export class Speaking extends BitField<SpeakingString> {

tsconfig.json:

{
    "compileOnSave": true,
    "compilerOptions": {
        "allowJs": true,
        "alwaysStrict": true,
        "experimentalDecorators": true,
        "module": "commonjs",
        "moduleResolution": "node",
        "noImplicitAny": true,
        "noUnusedParameters": true,
        "outDir": "build",
        "pretty": true,
        "sourceMap": true,
        "strict": true,
        "target": "esnext"
    },
    "exclude": [
        "node_modules"
    ],
    "include": [
        "src",
        "typings"
    ]
}

Related package.json sections:

    "main": "build/index.js",
    "scripts": {
        "prestart": "tsc",
        "start": "node .",
        "pretest": "tsc",
        "test": "node --inspect .",
        "debug": "nodemon -e ts --exec npm test"
    },
    "dependencies": {
        "@types/node": "^10.7.1",
        "discord.js": "github:discordjs/discord.js",
        "typescript": "^3.0.1"
    },
    "devDependencies": {
        "nodemon": "^1.18.3",
        "tslint": "^5.11.0"
    },

Let me know if there's anything else I can provide.

typings bug

Most helpful comment

To repeat the suggestion on discord, disabling strict as a compile option is a workaround for the issue, unsure if a good permanent resolution, however.

All 2 comments

To repeat the suggestion on discord, disabling strict as a compile option is a workaround for the issue, unsure if a good permanent resolution, however.

for me this worked:
npm i -D @types/node
and in tsconfig :
"types": ["node"]

Was this page helpful?
0 / 5 - 0 ratings

Related issues

LLamaFTL picture LLamaFTL  Â·  3Comments

BrandonCookeDev picture BrandonCookeDev  Â·  3Comments

shukriadams picture shukriadams  Â·  3Comments

Brawaru picture Brawaru  Â·  3Comments

iCrawl picture iCrawl  Â·  3Comments