[Bug]: TS2322: Type 'true' is not assignable to type 'false | undefined' (@SlashOption())
rdmchr opened this issue · comments
Radmacher commented
What happened?
IntelliJ is telling me that I can not assign true to the required option for @SlashOption()
.
Reproduction
- Create a new slash command
- Add a slash option (I used this:
@SlashOption("song", {type: 'STRING', description: "Either a link or a search term.", required: true}) song: string
) - When you try to compile your code you should get a similar error to this one:
D:\Projects\Shinobu\node_modules\.pnpm\ts-node@10.4.0_00264fd83560919cd06c986889baae0a\node_modules\ts-node\src\index.ts:750
return new TSError(diagnosticText, diagnosticCodes);
^
TSError: ⨯ Unable to compile TypeScript:
src/commands/play.ts:9:102 - error TS2322: Type 'true' is not assignable to type 'false | undefined'.
9 private play(@SlashOption("song", {type: 'STRING', description: "Either a link or a search term.", required: true}) song: string, interaction: CommandInteraction) {
~~~~~~~~
at createTSError (D:\Projects\Shinobu\node_modules\.pnpm\ts-node@10.4.0_00264fd83560919cd06c986889baae0a\node_modules\ts-node\src\index.ts:750:12)
at reportTSError (D:\Projects\Shinobu\node_modules\.pnpm\ts-node@10.4.0_00264fd83560919cd06c986889baae0a\node_modules\ts-node\src\index.ts:754:19)
at getOutput (D:\Projects\Shinobu\node_modules\.pnpm\ts-node@10.4.0_00264fd83560919cd06c986889baae0a\node_modules\ts-node\src\index.ts:941:36)
at Object.compile (D:\Projects\Shinobu\node_modules\.pnpm\ts-node@10.4.0_00264fd83560919cd06c986889baae0a\node_modules\ts-node\src\index.ts:1243:30)
at Module.m._compile (D:\Projects\Shinobu\node_modules\.pnpm\ts-node@10.4.0_00264fd83560919cd06c986889baae0a\node_modules\ts-node\src\index.ts:1370:30)
at Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Object.require.extensions.<computed> [as .ts] (D:\Projects\Shinobu\node_modules\.pnpm\ts-node@10.4.0_00264fd83560919cd06c986889baae0a\node_modules\ts-node\src\index.ts:1374:12)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:1005:19) {
diagnosticText: "\x1B[96msrc/commands/play.ts\x1B[0m:\x1B[93m9\x1B[0m:\x1B[93m102\x1B[0m - \x1B[91merror\x1B[0m\x1B[90m TS2322: \x1B[0mType 'true' is not assignable to type 'false | undefined'.\r\n" +
'\r\n' +
`\x1B[7m9\x1B[0m private play(@SlashOption("song", {type: 'STRING', description: "Either a link or a search term.", required: true}) song: string, interaction: CommandInteraction) {\r\n` +
'\x1B[7m \x1B[0m \x1B[91m ~~~~~~~~\x1B[0m\r\n',
diagnosticCodes: [ 2322 ]
}
Package
discordx
Version
Stable
Relevant log output
D:\Projects\Shinobu\node_modules\.pnpm\ts-node@10.4.0_00264fd83560919cd06c986889baae0a\node_modules\ts-node\src\index.ts:750
return new TSError(diagnosticText, diagnosticCodes);
^
TSError: ⨯ Unable to compile TypeScript:
src/commands/play.ts:9:102 - error TS2322: Type 'true' is not assignable to type 'false | undefined'.
9 private play(@SlashOption("song", {type: 'STRING', description: "Either a link or a search term.", required: true}) song: string, interaction: CommandInteraction) {
~~~~~~~~
at createTSError (D:\Projects\Shinobu\node_modules\.pnpm\ts-node@10.4.0_00264fd83560919cd06c986889baae0a\node_modules\ts-node\src\index.ts:750:12)
at reportTSError (D:\Projects\Shinobu\node_modules\.pnpm\ts-node@10.4.0_00264fd83560919cd06c986889baae0a\node_modules\ts-node\src\index.ts:754:19)
at getOutput (D:\Projects\Shinobu\node_modules\.pnpm\ts-node@10.4.0_00264fd83560919cd06c986889baae0a\node_modules\ts-node\src\index.ts:941:36)
at Object.compile (D:\Projects\Shinobu\node_modules\.pnpm\ts-node@10.4.0_00264fd83560919cd06c986889baae0a\node_modules\ts-node\src\index.ts:1243:30)
at Module.m._compile (D:\Projects\Shinobu\node_modules\.pnpm\ts-node@10.4.0_00264fd83560919cd06c986889baae0a\node_modules\ts-node\src\index.ts:1370:30)
at Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Object.require.extensions.<computed> [as .ts] (D:\Projects\Shinobu\node_modules\.pnpm\ts-node@10.4.0_00264fd83560919cd06c986889baae0a\node_modules\ts-node\src\index.ts:1374:12)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:1005:19) {
diagnosticText: "\x1B[96msrc/commands/play.ts\x1B[0m:\x1B[93m9\x1B[0m:\x1B[93m102\x1B[0m - \x1B[91merror\x1B[0m\x1B[90m TS2322: \x1B[0mType 'true' is not assignable to type 'false | undefined'.\r\n" +
'\r\n' +
`\x1B[7m9\x1B[0m private play(@SlashOption("song", {type: 'STRING', description: "Either a link or a search term.", required: true}) song: string, interaction: CommandInteraction) {\r\n` +
'\x1B[7m \x1B[0m \x1B[91m ~~~~~~~~\x1B[0m\r\n',
diagnosticCodes: [ 2322 ]
}
Code of Conduct
- I agree to follow this project's Code of Conduct
Vijay Meena (Samar) commented
@rdmchr in recent changes, you can only define required property to false only, you no need to define the required argument with true value because that is default value.
Radmacher commented
So if I want that option to be required, I just don't set any value?
Vijay Meena (Samar) commented
yes, no need to define required property because it's true in default nature.
however you can technically define undefine
instead true