From 34c0c4a82ee9f2f26e95b1852da2d4dc28ecd0d7 Mon Sep 17 00:00:00 2001 From: suneettipirneni Date: Mon, 8 Nov 2021 18:58:28 -0500 Subject: [PATCH 01/10] types(ApplicationCommandManager): deprecate old *Data types --- package-lock.json | 53 ++++++++++++++++++----------------- package.json | 1 + typings/index.d.ts | 70 ++++++++++++++++++++++++++++++++++++++-------- typings/tests.ts | 38 +++++++++++++++++-------- 4 files changed, 114 insertions(+), 48 deletions(-) diff --git a/package-lock.json b/package-lock.json index cd59125f5b8b..c0812751eca4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -37,6 +37,7 @@ "lint-staged": "^11.2.6", "prettier": "^2.4.1", "tslint": "^6.1.3", + "type-fest": "^2.5.2", "typescript": "^4.4.4" }, "engines": { @@ -6312,6 +6313,18 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/globals/node_modules/type-fest": { + "version": "0.20.2", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.20.2.tgz", + "integrity": "sha512-Ne+eE4r0/iWnpAxD852z3A+N0Bt5RN//NjJwRd2VFHEmrywxf5vsZlh4R6lixl6B+wz/8d+maTSAkN1FIkI3LQ==", + "dev": true, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/graceful-fs": { "version": "4.2.6", "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.6.tgz", @@ -9510,17 +9523,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/ow/node_modules/type-fest": { - "version": "2.5.2", - "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-2.5.2.tgz", - "integrity": "sha512-WMbytmAs5PUTqwGJRE+WoRrD2S0bYFtHX8k4Y/1l18CG5kqA3keJud9pPQ/r30FE9n8XRFCXF9BbccHIZzRYJw==", - "engines": { - "node": ">=12.20" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/p-limit": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-3.1.0.tgz", @@ -11578,12 +11580,11 @@ } }, "node_modules/type-fest": { - "version": "0.20.2", - "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.20.2.tgz", - "integrity": "sha512-Ne+eE4r0/iWnpAxD852z3A+N0Bt5RN//NjJwRd2VFHEmrywxf5vsZlh4R6lixl6B+wz/8d+maTSAkN1FIkI3LQ==", - "dev": true, + "version": "2.5.2", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-2.5.2.tgz", + "integrity": "sha512-WMbytmAs5PUTqwGJRE+WoRrD2S0bYFtHX8k4Y/1l18CG5kqA3keJud9pPQ/r30FE9n8XRFCXF9BbccHIZzRYJw==", "engines": { - "node": ">=10" + "node": ">=12.20" }, "funding": { "url": "https://github.com/sponsors/sindresorhus" @@ -17068,6 +17069,14 @@ "dev": true, "requires": { "type-fest": "^0.20.2" + }, + "dependencies": { + "type-fest": { + "version": "0.20.2", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.20.2.tgz", + "integrity": "sha512-Ne+eE4r0/iWnpAxD852z3A+N0Bt5RN//NjJwRd2VFHEmrywxf5vsZlh4R6lixl6B+wz/8d+maTSAkN1FIkI3LQ==", + "dev": true + } } }, "graceful-fs": { @@ -19518,11 +19527,6 @@ "requires": { "is-obj": "^2.0.0" } - }, - "type-fest": { - "version": "2.5.2", - "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-2.5.2.tgz", - "integrity": "sha512-WMbytmAs5PUTqwGJRE+WoRrD2S0bYFtHX8k4Y/1l18CG5kqA3keJud9pPQ/r30FE9n8XRFCXF9BbccHIZzRYJw==" } } }, @@ -21135,10 +21139,9 @@ "dev": true }, "type-fest": { - "version": "0.20.2", - "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.20.2.tgz", - "integrity": "sha512-Ne+eE4r0/iWnpAxD852z3A+N0Bt5RN//NjJwRd2VFHEmrywxf5vsZlh4R6lixl6B+wz/8d+maTSAkN1FIkI3LQ==", - "dev": true + "version": "2.5.2", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-2.5.2.tgz", + "integrity": "sha512-WMbytmAs5PUTqwGJRE+WoRrD2S0bYFtHX8k4Y/1l18CG5kqA3keJud9pPQ/r30FE9n8XRFCXF9BbccHIZzRYJw==" }, "typedarray": { "version": "0.0.6", diff --git a/package.json b/package.json index 451af9aba820..4382b4473a43 100644 --- a/package.json +++ b/package.json @@ -77,6 +77,7 @@ "lint-staged": "^11.2.6", "prettier": "^2.4.1", "tslint": "^6.1.3", + "type-fest": "^2.5.2", "typescript": "^4.4.4" }, "engines": { diff --git a/typings/index.d.ts b/typings/index.d.ts index d252ad7c8196..fd8a5dd90638 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -45,6 +45,7 @@ import { APIUser, GatewayVoiceServerUpdateDispatchData, GatewayVoiceStateUpdateDispatchData, + RESTPatchAPIApplicationCommandJSONBody, RESTPostAPIApplicationCommandsJSONBody, Snowflake, } from 'discord-api-types/v9'; @@ -137,6 +138,7 @@ import { RawWidgetData, RawWidgetMemberData, } from './rawDataTypes'; +import type { CamelCasedPropertiesDeep } from 'type-fest'; //#region Classes @@ -213,7 +215,7 @@ export class ApplicationCommand extends Base { public readonly manager: ApplicationCommandManager; public id: Snowflake; public name: string; - public options: ApplicationCommandOption[]; + public options: Camelize[]; public permissions: ApplicationCommandPermissionsManager< PermissionsFetchType, PermissionsFetchType, @@ -224,23 +226,31 @@ export class ApplicationCommand extends Base { public type: ApplicationCommandType; public version: Snowflake; public delete(): Promise>; + /** + * @deprecated use `Camelize)` instead + */ public edit(data: ApplicationCommandData): Promise>; + public edit( + data: Camelize, + ): Promise>; public equals( - command: ApplicationCommand | ApplicationCommandData | RawApplicationCommandData, + command: ApplicationCommand | Camelize | RawApplicationCommandData, enforceOptionorder?: boolean, ): boolean; public static optionsEqual( - existing: ApplicationCommandOption[], - options: ApplicationCommandOption[] | ApplicationCommandOptionData[] | APIApplicationCommandOption[], + existing: Camelize[], + options: Camelize[] | APIApplicationCommandOption[], enforceOptionorder?: boolean, ): boolean; private static _optionEquals( - existing: ApplicationCommandOption, - options: ApplicationCommandOption | ApplicationCommandOptionData | APIApplicationCommandOption, + existing: Camelize[], + options: Camelize[] | APIApplicationCommandOption, enforceOptionorder?: boolean, ): boolean; - private static transformOption(option: ApplicationCommandOptionData, received?: boolean): unknown; - private static transformCommand(command: ApplicationCommandData): RESTPostAPIApplicationCommandsJSONBody; + private static transformOption(option: Camelize, received?: boolean): unknown; + private static transformCommand( + command: Camelize, + ): RESTPostAPIApplicationCommandsJSONBody; private static isAPICommandData(command: object): command is RESTPostAPIApplicationCommandsJSONBody; } @@ -2627,7 +2637,11 @@ export abstract class CachedManager extends DataManager + | RESTPostAPIApplicationCommandsJSONBody; + +export type foo = Camelize['options']; export class ApplicationCommandManager< ApplicationCommandScope = ApplicationCommand<{ guild: GuildResolvable }>, @@ -2643,8 +2657,22 @@ export class ApplicationCommandManager< null >; private commandPath({ id, guildId }: { id?: Snowflake; guildId?: Snowflake }): unknown; + /** + * @deprecated use `create(ApplicationCommandDataResolvable)` instead + */ + public create( + command: ApplicationCommandData | RESTPostAPIApplicationCommandsJSONBody, + ): Promise; + /** + * @deprecated use `create(ApplicationCommandDataResolvable, Snowflake)` instead + */ + public create( + command: ApplicationCommandData | RESTPostAPIApplicationCommandsJSONBody, + guildId: Snowflake, + ): Promise; public create(command: ApplicationCommandDataResolvable): Promise; - public create(command: ApplicationCommandDataResolvable, guildId: Snowflake): Promise; + /** @deprecated use `delete(ApplicationCommandDataResolvable, Snowflake?)` instead */ + public delete(command: ApplicationCommandData, guildId?: Snowflake): Promise; public delete(command: ApplicationCommandResolvable, guildId?: Snowflake): Promise; public edit( command: ApplicationCommandResolvable, @@ -2665,13 +2693,20 @@ export class ApplicationCommandManager< id?: Snowflake, options?: FetchApplicationCommandOptions, ): Promise>; + /** @deprecated Use `set(ApplicationCommandResolvable)` instead */ + public set(commands: ApplicationCommandData[]): Promise>; + /** @deprecated Use `set(ApplicationCommandResolvable, Snowflake)` instead */ + public set( + commands: ApplicationCommandData[], + guildId: Snowflake, + ): Promise>; public set(commands: ApplicationCommandDataResolvable[]): Promise>; public set( commands: ApplicationCommandDataResolvable[], guildId: Snowflake, ): Promise>; private static transformCommand( - command: ApplicationCommandData, + command: Camelize, ): Omit; } @@ -2736,7 +2771,9 @@ export class GuildApplicationCommandManager extends ApplicationCommandManager); public guild: Guild; public create(command: ApplicationCommandDataResolvable): Promise; - public delete(command: ApplicationCommandResolvable): Promise; + /** @deprecated use `delete(ApplicationCommandDataResolvable, Snowflake?)` instead */ + public delete(command: ApplicationCommandData, guildId?: Snowflake): Promise; + public delete(command: ApplicationCommandResolvable, guildId?: Snowflake): Promise; public edit( command: ApplicationCommandResolvable, data: ApplicationCommandDataResolvable, @@ -2744,6 +2781,8 @@ export class GuildApplicationCommandManager extends ApplicationCommandManager; public fetch(options: BaseFetchOptions): Promise>; public fetch(id?: undefined, options?: BaseFetchOptions): Promise>; + /** @deprecated Use `set(ApplicationCommandResolvable)` instead */ + public set(commands: ApplicationCommandData[]): Promise>; public set(commands: ApplicationCommandDataResolvable[]): Promise>; } @@ -3328,6 +3367,9 @@ export interface ChatInputApplicationCommandData extends BaseApplicationCommandD options?: ApplicationCommandOptionData[]; } +/** + * @deprecated use `Camelize` instead + */ export type ApplicationCommandData = | UserApplicationCommandData | MessageApplicationCommandData @@ -3382,6 +3424,9 @@ export interface ApplicationCommandNonOptions extends BaseApplicationCommandOpti type: Exclude; } +// The original name for the utility type is really long, so this is just an alias for it. +export type Camelize = CamelCasedPropertiesDeep; +/** @deprecated Use `Camelize` instead. */ export type ApplicationCommandOptionData = | ApplicationCommandSubGroupData | ApplicationCommandNonOptionsData @@ -3389,6 +3434,7 @@ export type ApplicationCommandOptionData = | ApplicationCommandChoicesData | ApplicationCommandSubCommandData; +/** @deprecated use `Camelize` instead */ export type ApplicationCommandOption = | ApplicationCommandSubGroup | ApplicationCommandNonOptions diff --git a/typings/tests.ts b/typings/tests.ts index fe494f5d6708..21971cd56068 100644 --- a/typings/tests.ts +++ b/typings/tests.ts @@ -1,4 +1,4 @@ -import type { +import { APIGuildMember, APIInteractionGuildMember, APIMessage, @@ -7,18 +7,20 @@ import type { APIInteractionDataResolvedGuildMember, APIInteractionDataResolvedChannel, APIRole, + ChannelType, + ApplicationCommandOptionType, + APIApplicationCommand, + APIApplicationCommandOption, + APIApplicationCommandSubCommandOptions, } from 'discord-api-types/v9'; import { ApplicationCommand, ApplicationCommandChannelOptionData, ApplicationCommandChoicesData, - ApplicationCommandData, ApplicationCommandManager, ApplicationCommandNonOptionsData, - ApplicationCommandOptionData, ApplicationCommandResolvable, ApplicationCommandSubCommandData, - ApplicationCommandSubGroupData, BaseCommandInteraction, ButtonInteraction, CacheType, @@ -30,7 +32,6 @@ import { CommandInteraction, CommandInteractionOption, CommandInteractionOptionResolver, - CommandOptionChoiceResolvableType, CommandOptionNonChoiceResolvableType, Constants, ContextMenuInteraction, @@ -80,6 +81,7 @@ import { User, VoiceChannel, Shard, + Camelize, } from '.'; import type { ApplicationCommandOptionTypes } from './enums'; @@ -685,6 +687,20 @@ client.login('absolutely-valid-token'); // Test client conditional types client.on('ready', client => { assertType>(client); + + // Test camelized post command data. + client.application.commands.create({ + name: 'Foo', + description: 'Bar', + options: [ + { + name: 'test', + description: 'test', + type: ApplicationCommandOptionType.Channel, + channelTypes: [ChannelType.GuildCategory], + }, + ], + }); }); declare const loggedInClient: Client; @@ -787,7 +803,7 @@ assertType<1>(Constants.Status.CONNECTING); assertType<0>(Constants.Opcodes.DISPATCH); assertType<2>(Constants.ClientApplicationAssetTypes.BIG); -declare const applicationCommandData: ApplicationCommandData; +declare const applicationCommandData: Camelize; declare const applicationCommandResolvable: ApplicationCommandResolvable; declare const applicationCommandManager: ApplicationCommandManager; { @@ -809,7 +825,7 @@ declare const applicationCommandManager: ApplicationCommandManager; ); } -declare const applicationNonChoiceOptionData: ApplicationCommandOptionData & { +declare const applicationNonChoiceOptionData: APIApplicationCommandOption & { type: CommandOptionNonChoiceResolvableType; }; { @@ -819,18 +835,18 @@ declare const applicationNonChoiceOptionData: ApplicationCommandOptionData & { applicationNonChoiceOptionData.choices; } -declare const applicationChoiceOptionData: ApplicationCommandOptionData & { type: CommandOptionChoiceResolvableType }; +declare const applicationChoiceOptionData: APIApplicationCommandOption & { type: ApplicationCommandOptionType.String }; { // Choices should be available. applicationChoiceOptionData.choices; } -declare const applicationSubGroupCommandData: ApplicationCommandSubGroupData; +declare const applicationSubGroupCommandData: Camelize; { - assertType<'SUB_COMMAND_GROUP' | ApplicationCommandOptionTypes.SUB_COMMAND_GROUP>( + assertType( applicationSubGroupCommandData.type, ); - assertType(applicationSubGroupCommandData.options); + assertType(applicationSubGroupCommandData.options); } declare const applicationSubCommandData: ApplicationCommandSubCommandData; From 40b0295002b2907a8b3ace6322e0b9588c25940b Mon Sep 17 00:00:00 2001 From: suneettipirneni Date: Tue, 9 Nov 2021 09:18:54 -0500 Subject: [PATCH 02/10] chore: use custom camelizer --- package-lock.json | 1 - package.json | 1 - typings/index.d.ts | 12 ++++++++++-- typings/tests.ts | 1 - 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index c0812751eca4..73c43e77ef7f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -37,7 +37,6 @@ "lint-staged": "^11.2.6", "prettier": "^2.4.1", "tslint": "^6.1.3", - "type-fest": "^2.5.2", "typescript": "^4.4.4" }, "engines": { diff --git a/package.json b/package.json index 4382b4473a43..451af9aba820 100644 --- a/package.json +++ b/package.json @@ -77,7 +77,6 @@ "lint-staged": "^11.2.6", "prettier": "^2.4.1", "tslint": "^6.1.3", - "type-fest": "^2.5.2", "typescript": "^4.4.4" }, "engines": { diff --git a/typings/index.d.ts b/typings/index.d.ts index fd8a5dd90638..d7a45049bfb7 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -3424,8 +3424,16 @@ export interface ApplicationCommandNonOptions extends BaseApplicationCommandOpti type: Exclude; } -// The original name for the utility type is really long, so this is just an alias for it. -export type Camelize = CamelCasedPropertiesDeep; +export type CamelCase = S extends `${infer FirstPart}_${infer Rest}` + ? `${FirstPart}${Capitalize>}` + : S; + +export type Camelize = T extends Array + ? Array> + : T extends object + ? { [Key in keyof T as CamelCase]: Camelize } + : T; + /** @deprecated Use `Camelize` instead. */ export type ApplicationCommandOptionData = | ApplicationCommandSubGroupData diff --git a/typings/tests.ts b/typings/tests.ts index 21971cd56068..d3cc84de2dec 100644 --- a/typings/tests.ts +++ b/typings/tests.ts @@ -834,7 +834,6 @@ declare const applicationNonChoiceOptionData: APIApplicationCommandOption & { // @ts-expect-error applicationNonChoiceOptionData.choices; } - declare const applicationChoiceOptionData: APIApplicationCommandOption & { type: ApplicationCommandOptionType.String }; { // Choices should be available. From 3f1d6d27f319bae95cad60c1685e239450816c6a Mon Sep 17 00:00:00 2001 From: suneettipirneni Date: Tue, 9 Nov 2021 09:32:10 -0500 Subject: [PATCH 03/10] chore: make tslint happy --- tslint.json | 3 ++- typings/index.d.ts | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/tslint.json b/tslint.json index d66f7bdf3b60..151105a8b488 100644 --- a/tslint.json +++ b/tslint.json @@ -24,6 +24,7 @@ "array-type": [true, "array"], "one-line": false, "no-any-union": false, - "void-return": false + "void-return": false, + "unified-signatures": false } } diff --git a/typings/index.d.ts b/typings/index.d.ts index d7a45049bfb7..5def1c2007fa 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -3428,8 +3428,9 @@ export type CamelCase = S extends `${infer FirstPart}_${infer ? `${FirstPart}${Capitalize>}` : S; +// tslint:disable-next-line:array-type export type Camelize = T extends Array - ? Array> + ? Camelize[] : T extends object ? { [Key in keyof T as CamelCase]: Camelize } : T; From bd7cde0d01e8c17ff942eef00bc9992e3163fe51 Mon Sep 17 00:00:00 2001 From: suneettipirneni Date: Tue, 9 Nov 2021 11:14:24 -0500 Subject: [PATCH 04/10] chore: revert package-lock --- package-lock.json | 52 +++++++++++++++++++++++------------------------ 1 file changed, 25 insertions(+), 27 deletions(-) diff --git a/package-lock.json b/package-lock.json index 73c43e77ef7f..cd59125f5b8b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6312,18 +6312,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/globals/node_modules/type-fest": { - "version": "0.20.2", - "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.20.2.tgz", - "integrity": "sha512-Ne+eE4r0/iWnpAxD852z3A+N0Bt5RN//NjJwRd2VFHEmrywxf5vsZlh4R6lixl6B+wz/8d+maTSAkN1FIkI3LQ==", - "dev": true, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/graceful-fs": { "version": "4.2.6", "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.6.tgz", @@ -9522,6 +9510,17 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/ow/node_modules/type-fest": { + "version": "2.5.2", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-2.5.2.tgz", + "integrity": "sha512-WMbytmAs5PUTqwGJRE+WoRrD2S0bYFtHX8k4Y/1l18CG5kqA3keJud9pPQ/r30FE9n8XRFCXF9BbccHIZzRYJw==", + "engines": { + "node": ">=12.20" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/p-limit": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-3.1.0.tgz", @@ -11579,11 +11578,12 @@ } }, "node_modules/type-fest": { - "version": "2.5.2", - "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-2.5.2.tgz", - "integrity": "sha512-WMbytmAs5PUTqwGJRE+WoRrD2S0bYFtHX8k4Y/1l18CG5kqA3keJud9pPQ/r30FE9n8XRFCXF9BbccHIZzRYJw==", + "version": "0.20.2", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.20.2.tgz", + "integrity": "sha512-Ne+eE4r0/iWnpAxD852z3A+N0Bt5RN//NjJwRd2VFHEmrywxf5vsZlh4R6lixl6B+wz/8d+maTSAkN1FIkI3LQ==", + "dev": true, "engines": { - "node": ">=12.20" + "node": ">=10" }, "funding": { "url": "https://github.com/sponsors/sindresorhus" @@ -17068,14 +17068,6 @@ "dev": true, "requires": { "type-fest": "^0.20.2" - }, - "dependencies": { - "type-fest": { - "version": "0.20.2", - "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.20.2.tgz", - "integrity": "sha512-Ne+eE4r0/iWnpAxD852z3A+N0Bt5RN//NjJwRd2VFHEmrywxf5vsZlh4R6lixl6B+wz/8d+maTSAkN1FIkI3LQ==", - "dev": true - } } }, "graceful-fs": { @@ -19526,6 +19518,11 @@ "requires": { "is-obj": "^2.0.0" } + }, + "type-fest": { + "version": "2.5.2", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-2.5.2.tgz", + "integrity": "sha512-WMbytmAs5PUTqwGJRE+WoRrD2S0bYFtHX8k4Y/1l18CG5kqA3keJud9pPQ/r30FE9n8XRFCXF9BbccHIZzRYJw==" } } }, @@ -21138,9 +21135,10 @@ "dev": true }, "type-fest": { - "version": "2.5.2", - "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-2.5.2.tgz", - "integrity": "sha512-WMbytmAs5PUTqwGJRE+WoRrD2S0bYFtHX8k4Y/1l18CG5kqA3keJud9pPQ/r30FE9n8XRFCXF9BbccHIZzRYJw==" + "version": "0.20.2", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.20.2.tgz", + "integrity": "sha512-Ne+eE4r0/iWnpAxD852z3A+N0Bt5RN//NjJwRd2VFHEmrywxf5vsZlh4R6lixl6B+wz/8d+maTSAkN1FIkI3LQ==", + "dev": true }, "typedarray": { "version": "0.0.6", From d3b28a821d258ef1b0e2631c09c761e42e27b084 Mon Sep 17 00:00:00 2001 From: Suneet Tipirneni Date: Tue, 9 Nov 2021 12:41:28 -0500 Subject: [PATCH 05/10] chore: use type-fest dep --- package-lock.json | 53 ++++++++++++++++++++++++---------------------- package.json | 1 + typings/index.d.ts | 12 ++--------- 3 files changed, 31 insertions(+), 35 deletions(-) diff --git a/package-lock.json b/package-lock.json index cd59125f5b8b..2b759624833e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17,6 +17,7 @@ "@types/ws": "^8.2.0", "discord-api-types": "^0.24.0", "node-fetch": "^2.6.1", + "type-fest": "^2.5.3", "ws": "^8.2.3" }, "devDependencies": { @@ -6312,6 +6313,18 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/globals/node_modules/type-fest": { + "version": "0.20.2", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.20.2.tgz", + "integrity": "sha512-Ne+eE4r0/iWnpAxD852z3A+N0Bt5RN//NjJwRd2VFHEmrywxf5vsZlh4R6lixl6B+wz/8d+maTSAkN1FIkI3LQ==", + "dev": true, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/graceful-fs": { "version": "4.2.6", "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.6.tgz", @@ -9510,17 +9523,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/ow/node_modules/type-fest": { - "version": "2.5.2", - "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-2.5.2.tgz", - "integrity": "sha512-WMbytmAs5PUTqwGJRE+WoRrD2S0bYFtHX8k4Y/1l18CG5kqA3keJud9pPQ/r30FE9n8XRFCXF9BbccHIZzRYJw==", - "engines": { - "node": ">=12.20" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/p-limit": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-3.1.0.tgz", @@ -11578,12 +11580,11 @@ } }, "node_modules/type-fest": { - "version": "0.20.2", - "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.20.2.tgz", - "integrity": "sha512-Ne+eE4r0/iWnpAxD852z3A+N0Bt5RN//NjJwRd2VFHEmrywxf5vsZlh4R6lixl6B+wz/8d+maTSAkN1FIkI3LQ==", - "dev": true, + "version": "2.5.3", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-2.5.3.tgz", + "integrity": "sha512-7VNmE7FlsrdcWjKbtuRuynZz96Gmf35p5DvoR2tbceNP0vd58ISx87PvUUInlhtRC49vSX6qlxEKc7AoiHRirg==", "engines": { - "node": ">=10" + "node": ">=12.20" }, "funding": { "url": "https://github.com/sponsors/sindresorhus" @@ -17068,6 +17069,14 @@ "dev": true, "requires": { "type-fest": "^0.20.2" + }, + "dependencies": { + "type-fest": { + "version": "0.20.2", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.20.2.tgz", + "integrity": "sha512-Ne+eE4r0/iWnpAxD852z3A+N0Bt5RN//NjJwRd2VFHEmrywxf5vsZlh4R6lixl6B+wz/8d+maTSAkN1FIkI3LQ==", + "dev": true + } } }, "graceful-fs": { @@ -19518,11 +19527,6 @@ "requires": { "is-obj": "^2.0.0" } - }, - "type-fest": { - "version": "2.5.2", - "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-2.5.2.tgz", - "integrity": "sha512-WMbytmAs5PUTqwGJRE+WoRrD2S0bYFtHX8k4Y/1l18CG5kqA3keJud9pPQ/r30FE9n8XRFCXF9BbccHIZzRYJw==" } } }, @@ -21135,10 +21139,9 @@ "dev": true }, "type-fest": { - "version": "0.20.2", - "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.20.2.tgz", - "integrity": "sha512-Ne+eE4r0/iWnpAxD852z3A+N0Bt5RN//NjJwRd2VFHEmrywxf5vsZlh4R6lixl6B+wz/8d+maTSAkN1FIkI3LQ==", - "dev": true + "version": "2.5.3", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-2.5.3.tgz", + "integrity": "sha512-7VNmE7FlsrdcWjKbtuRuynZz96Gmf35p5DvoR2tbceNP0vd58ISx87PvUUInlhtRC49vSX6qlxEKc7AoiHRirg==" }, "typedarray": { "version": "0.0.6", diff --git a/package.json b/package.json index 451af9aba820..a7da2a4df7ca 100644 --- a/package.json +++ b/package.json @@ -57,6 +57,7 @@ "@types/ws": "^8.2.0", "discord-api-types": "^0.24.0", "node-fetch": "^2.6.1", + "type-fest": "^2.5.3", "ws": "^8.2.3" }, "devDependencies": { diff --git a/typings/index.d.ts b/typings/index.d.ts index 5def1c2007fa..8ec1f7235cbb 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -3424,16 +3424,8 @@ export interface ApplicationCommandNonOptions extends BaseApplicationCommandOpti type: Exclude; } -export type CamelCase = S extends `${infer FirstPart}_${infer Rest}` - ? `${FirstPart}${Capitalize>}` - : S; - -// tslint:disable-next-line:array-type -export type Camelize = T extends Array - ? Camelize[] - : T extends object - ? { [Key in keyof T as CamelCase]: Camelize } - : T; +// Type alias since the lib name is very long. +export type Camelize = CamelCasedPropertiesDeep; /** @deprecated Use `Camelize` instead. */ export type ApplicationCommandOptionData = From 93be0763062a93111632731362b64cd44e24ed66 Mon Sep 17 00:00:00 2001 From: Suneet Tipirneni Date: Tue, 9 Nov 2021 12:45:05 -0500 Subject: [PATCH 06/10] chore: fix doc formatting --- typings/index.d.ts | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/typings/index.d.ts b/typings/index.d.ts index 8ec1f7235cbb..05a42879e297 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -226,9 +226,7 @@ export class ApplicationCommand extends Base { public type: ApplicationCommandType; public version: Snowflake; public delete(): Promise>; - /** - * @deprecated use `Camelize)` instead - */ + /** @deprecated use `edit(Camelize)` instead */ public edit(data: ApplicationCommandData): Promise>; public edit( data: Camelize, @@ -2657,15 +2655,11 @@ export class ApplicationCommandManager< null >; private commandPath({ id, guildId }: { id?: Snowflake; guildId?: Snowflake }): unknown; - /** - * @deprecated use `create(ApplicationCommandDataResolvable)` instead - */ + /** @deprecated use `create(ApplicationCommandDataResolvable)` instead */ public create( command: ApplicationCommandData | RESTPostAPIApplicationCommandsJSONBody, ): Promise; - /** - * @deprecated use `create(ApplicationCommandDataResolvable, Snowflake)` instead - */ + /** @deprecated use `create(ApplicationCommandDataResolvable, Snowflake)` instead */ public create( command: ApplicationCommandData | RESTPostAPIApplicationCommandsJSONBody, guildId: Snowflake, @@ -3367,9 +3361,7 @@ export interface ChatInputApplicationCommandData extends BaseApplicationCommandD options?: ApplicationCommandOptionData[]; } -/** - * @deprecated use `Camelize` instead - */ +/** @deprecated use `Camelize` instead */ export type ApplicationCommandData = | UserApplicationCommandData | MessageApplicationCommandData From 9d7152f0fdcd879cad654fe4fdd658fac57ceb02 Mon Sep 17 00:00:00 2001 From: Suneet Tipirneni Date: Tue, 9 Nov 2021 13:29:32 -0500 Subject: [PATCH 07/10] chore: remove debug code --- typings/index.d.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/typings/index.d.ts b/typings/index.d.ts index 05a42879e297..c0021eacabab 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -2639,8 +2639,6 @@ export type ApplicationCommandDataResolvable = | Camelize | RESTPostAPIApplicationCommandsJSONBody; -export type foo = Camelize['options']; - export class ApplicationCommandManager< ApplicationCommandScope = ApplicationCommand<{ guild: GuildResolvable }>, PermissionsOptionsExtras = { guild: GuildResolvable }, From 6adffd471287cc861887e0c0549dd8f8ccb996c8 Mon Sep 17 00:00:00 2001 From: suneettipirneni Date: Tue, 9 Nov 2021 20:38:06 -0500 Subject: [PATCH 08/10] chore: remove unused tslint directives --- typings/index.d.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/typings/index.d.ts b/typings/index.d.ts index c0021eacabab..80993e089c0d 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -2339,10 +2339,8 @@ export class WebhookClient extends WebhookMixin(BaseClient) { options: string | MessagePayload | WebhookEditMessageOptions, ): Promise; public fetchMessage(message: Snowflake, options?: WebhookFetchMessageOptions): Promise; - /* tslint:disable:unified-signatures */ /** @deprecated */ public fetchMessage(message: Snowflake, cache?: boolean): Promise; - /* tslint:enable:unified-signatures */ public send(options: string | MessagePayload | WebhookMessageOptions): Promise; } @@ -3093,10 +3091,8 @@ export interface PartialWebhookFields { options: string | MessagePayload | WebhookEditMessageOptions, ): Promise; fetchMessage(message: Snowflake | '@original', options?: WebhookFetchMessageOptions): Promise; - /* tslint:disable:unified-signatures */ /** @deprecated */ fetchMessage(message: Snowflake | '@original', cache?: boolean): Promise; - /* tslint:enable:unified-signatures */ send(options: string | MessagePayload | WebhookMessageOptions): Promise; } From 59bd1b711f0fe35856aaa6f8ef5df5ed2199f3ba Mon Sep 17 00:00:00 2001 From: Suneet Tipirneni Date: Tue, 23 Nov 2021 11:13:05 -0500 Subject: [PATCH 09/10] types: remove unneeded test --- typings/tests.ts | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/typings/tests.ts b/typings/tests.ts index 31ea2fd3a236..eb9477136e5e 100644 --- a/typings/tests.ts +++ b/typings/tests.ts @@ -32,7 +32,6 @@ import { CommandInteraction, CommandInteractionOption, CommandInteractionOptionResolver, - CommandOptionNonChoiceResolvableType, Constants, ContextMenuInteraction, DMChannel, @@ -889,21 +888,6 @@ declare const applicationCommandManager: ApplicationCommandManager; ); } -declare const applicationNonChoiceOptionData: APIApplicationCommandOption & { - type: CommandOptionNonChoiceResolvableType; -}; -{ - // Options aren't allowed on this command type. - - // @ts-expect-error - applicationNonChoiceOptionData.choices; -} -declare const applicationChoiceOptionData: APIApplicationCommandOption & { type: ApplicationCommandOptionType.String }; -{ - // Choices should be available. - applicationChoiceOptionData.choices; -} - declare const applicationSubGroupCommandData: Camelize; { assertType( From b90f67cb7f9fb019cc5dc9d4a7f2421fd0f307df Mon Sep 17 00:00:00 2001 From: Suneet Tipirneni Date: Tue, 23 Nov 2021 12:53:26 -0500 Subject: [PATCH 10/10] chore: fix tests --- typings/index.test-d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/typings/index.test-d.ts b/typings/index.test-d.ts index 0c6ef6dd163b..cbaf73061d12 100644 --- a/typings/index.test-d.ts +++ b/typings/index.test-d.ts @@ -831,7 +831,7 @@ declare const applicationSubGroupCommandData: Camelize( applicationSubGroupCommandData.type, ); - expectType(applicationSubGroupCommandData.options); + expectAssignable(applicationSubGroupCommandData.options); } declare const applicationSubCommandData: ApplicationCommandSubCommandData;