mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-15 11:03:30 +01:00
chore: use descriptive type parameter names (#9937)
* chore: use descriptive type parameter names * refactor: requested changes --------- Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
@@ -54,15 +54,15 @@ export type AnyComponentBuilder = MessageActionRowComponentBuilder | ModalAction
|
||||
/**
|
||||
* A builder that creates API-compatible JSON data for action rows.
|
||||
*
|
||||
* @typeParam T - The types of components this action row holds
|
||||
* @typeParam ComponentType - The types of components this action row holds
|
||||
*/
|
||||
export class ActionRowBuilder<T extends AnyComponentBuilder> extends ComponentBuilder<
|
||||
export class ActionRowBuilder<ComponentType extends AnyComponentBuilder> extends ComponentBuilder<
|
||||
APIActionRowComponent<APIMessageActionRowComponent | APIModalActionRowComponent>
|
||||
> {
|
||||
/**
|
||||
* The components within this action row.
|
||||
*/
|
||||
public readonly components: T[];
|
||||
public readonly components: ComponentType[];
|
||||
|
||||
/**
|
||||
* Creates a new action row from API data.
|
||||
@@ -100,7 +100,7 @@ export class ActionRowBuilder<T extends AnyComponentBuilder> extends ComponentBu
|
||||
*/
|
||||
public constructor({ components, ...data }: Partial<APIActionRowComponent<APIActionRowComponentTypes>> = {}) {
|
||||
super({ type: ComponentType.ActionRow, ...data });
|
||||
this.components = (components?.map((component) => createComponentBuilder(component)) ?? []) as T[];
|
||||
this.components = (components?.map((component) => createComponentBuilder(component)) ?? []) as ComponentType[];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -108,7 +108,7 @@ export class ActionRowBuilder<T extends AnyComponentBuilder> extends ComponentBu
|
||||
*
|
||||
* @param components - The components to add
|
||||
*/
|
||||
public addComponents(...components: RestOrArray<T>) {
|
||||
public addComponents(...components: RestOrArray<ComponentType>) {
|
||||
this.components.push(...normalizeArray(components));
|
||||
return this;
|
||||
}
|
||||
@@ -118,7 +118,7 @@ export class ActionRowBuilder<T extends AnyComponentBuilder> extends ComponentBu
|
||||
*
|
||||
* @param components - The components to set
|
||||
*/
|
||||
public setComponents(...components: RestOrArray<T>) {
|
||||
public setComponents(...components: RestOrArray<ComponentType>) {
|
||||
this.components.splice(0, this.components.length, ...normalizeArray(components));
|
||||
return this;
|
||||
}
|
||||
@@ -126,10 +126,10 @@ export class ActionRowBuilder<T extends AnyComponentBuilder> extends ComponentBu
|
||||
/**
|
||||
* {@inheritDoc ComponentBuilder.toJSON}
|
||||
*/
|
||||
public toJSON(): APIActionRowComponent<ReturnType<T['toJSON']>> {
|
||||
public toJSON(): APIActionRowComponent<ReturnType<ComponentType['toJSON']>> {
|
||||
return {
|
||||
...this.data,
|
||||
components: this.components.map((component) => component.toJSON()),
|
||||
} as APIActionRowComponent<ReturnType<T['toJSON']>>;
|
||||
} as APIActionRowComponent<ReturnType<ComponentType['toJSON']>>;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,21 +55,23 @@ export interface MappedComponentTypes {
|
||||
/**
|
||||
* Factory for creating components from API data.
|
||||
*
|
||||
* @typeParam T - The type of component to use
|
||||
* @typeParam ComponentType - The type of component to use
|
||||
* @param data - The API data to transform to a component class
|
||||
*/
|
||||
export function createComponentBuilder<T extends keyof MappedComponentTypes>(
|
||||
export function createComponentBuilder<ComponentType extends keyof MappedComponentTypes>(
|
||||
// eslint-disable-next-line @typescript-eslint/sort-type-constituents
|
||||
data: (APIModalComponent | APIMessageComponent) & { type: T },
|
||||
): MappedComponentTypes[T];
|
||||
data: (APIModalComponent | APIMessageComponent) & { type: ComponentType },
|
||||
): MappedComponentTypes[ComponentType];
|
||||
|
||||
/**
|
||||
* Factory for creating components from API data.
|
||||
*
|
||||
* @typeParam C - The type of component to use
|
||||
* @typeParam ComponentBuilder - The type of component to use
|
||||
* @param data - The API data to transform to a component class
|
||||
*/
|
||||
export function createComponentBuilder<C extends MessageComponentBuilder | ModalComponentBuilder>(data: C): C;
|
||||
export function createComponentBuilder<ComponentBuilder extends MessageComponentBuilder | ModalComponentBuilder>(
|
||||
data: ComponentBuilder,
|
||||
): ComponentBuilder;
|
||||
|
||||
export function createComponentBuilder(
|
||||
data: APIMessageComponent | APIModalComponent | MessageComponentBuilder,
|
||||
|
||||
Reference in New Issue
Block a user