Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

types: Allow choice's value type to be strictly inferred #8529

Merged
merged 3 commits into from Aug 20, 2022

Conversation

Jiralite
Copy link
Member

Please describe the changes this PR makes and why it should be merged:
The following code will not yield an error despite the type of the option being known:

import { ApplicationCommandOptionType, ApplicationCommandType, Guild } from "discord.js"

declare const guild: Guild;

guild.commands.create({
  name: "test",
  description: "test",
  type: ApplicationCommandType.ChatInput,
  options: [
    {
      type: ApplicationCommandOptionType.String,
      name: "test",
      description: "test",
      choices: [
        {
          name: "test",
          value: 0 // No error!
        },
      ],
      required: true
    }
  ]
});

This pull request strengthens the types around here and resolves #8528.

Status and versioning classification:

  • Code changes have been tested against the Discord API, or there are no code changes
  • I know how to update typings and have done so, or typings don't need updating

@vercel
Copy link

vercel bot commented Aug 20, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Updated
discord-js ⬜️ Ignored (Inspect) Aug 20, 2022 at 8:24PM (UTC)

@codecov
Copy link

codecov bot commented Aug 20, 2022

Codecov Report

Merging #8529 (0d25854) into main (8028813) will increase coverage by 7.72%.
The diff coverage is n/a.

❗ Current head 0d25854 differs from pull request most recent head 614bcd4. Consider uploading reports for the commit 614bcd4 to get more accurate results

@@            Coverage Diff             @@
##             main    #8529      +/-   ##
==========================================
+ Coverage   78.73%   86.45%   +7.72%     
==========================================
  Files          22       87      +65     
  Lines        3503     8462    +4959     
  Branches      320     1105     +785     
==========================================
+ Hits         2758     7316    +4558     
- Misses        741     1103     +362     
- Partials        4       43      +39     
Flag Coverage Δ
builders 100.00% <ø> (?)
collection 100.00% <ø> (?)
proxy 73.28% <ø> (?)
rest 92.53% <ø> (ø)
utilities 100.00% <ø> (?)
voice 64.08% <ø> (?)
ws 59.57% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
packages/voice/src/receive/SpeakingMap.ts 100.00% <0.00%> (ø)
...ders/src/components/selectMenu/SelectMenuOption.ts 100.00% <0.00%> (ø)
.../interactions/slashCommands/options/mentionable.ts 100.00% <0.00%> (ø)
packages/voice/src/util/Secretbox.ts 33.33% <0.00%> (ø)
packages/voice/src/audio/AudioPlayerError.ts 0.00% <0.00%> (ø)
packages/voice/src/audio/TransformerGraph.ts 74.60% <0.00%> (ø)
packages/voice/src/util/entersState.ts 100.00% <0.00%> (ø)
packages/collection/src/collection.ts 100.00% <0.00%> (ø)
.../src/interactions/slashCommands/options/boolean.ts 100.00% <0.00%> (ø)
...eractions/slashCommands/SlashCommandSubcommands.ts 100.00% <0.00%> (ø)
... and 55 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

packages/discord.js/typings/index.d.ts Outdated Show resolved Hide resolved
packages/discord.js/typings/index.d.ts Outdated Show resolved Hide resolved
@Jiralite Jiralite force-pushed the types/choice-value-type-param branch from d440170 to c46c350 Compare August 20, 2022 14:30
Copy link
Member

@SpaceEEC SpaceEEC left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some tests for these would be nice 🙏

@kodiakhq kodiakhq bot merged commit b3f7c32 into discordjs:main Aug 20, 2022
@Jiralite Jiralite deleted the types/choice-value-type-param branch August 20, 2022 20:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Wrong type def in ApplicationCommandOptionChoiceData.value
5 participants