Skip to content

Commit 975d5f1

Browse files
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>
1 parent 4ff3ea4 commit 975d5f1

File tree

34 files changed

+1097
-888
lines changed

34 files changed

+1097
-888
lines changed

apps/website/src/components/ItemLink.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { usePathname } from 'next/navigation';
66
import type { PropsWithChildren } from 'react';
77
import { useCurrentPathMeta } from '~/hooks/useCurrentPathMeta';
88

9-
export interface ItemLinkProps<T extends string> extends Omit<LinkProps<T>, 'href'> {
9+
export interface ItemLinkProps<Route extends string> extends Omit<LinkProps<Route>, 'href'> {
1010
readonly className?: string;
1111
/**
1212
* The URI of the api item to link to. (e.g. `/RestManager`)
@@ -29,7 +29,7 @@ export interface ItemLinkProps<T extends string> extends Omit<LinkProps<T>, 'hre
2929
* This component only needs the relative path to the item, and will automatically
3030
* generate the full path to the item client-side.
3131
*/
32-
export function ItemLink<T extends string>(props: PropsWithChildren<ItemLinkProps<T>>) {
32+
export function ItemLink<Route extends string>(props: PropsWithChildren<ItemLinkProps<Route>>) {
3333
const pathname = usePathname();
3434
const { packageName, version } = useCurrentPathMeta();
3535

apps/website/src/util/members.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import type { ApiItem, ApiItemContainerMixin } from '@discordjs/api-extractor-mo
66
* @param parent - The parent to resolve the inherited members of.
77
* @param predicate - A predicate to filter the members by.
88
*/
9-
export function resolveMembers<T extends ApiItem>(
9+
export function resolveMembers<WantedItem extends ApiItem>(
1010
parent: ApiItemContainerMixin,
11-
predicate: (item: ApiItem) => item is T,
11+
predicate: (item: ApiItem) => item is WantedItem,
1212
) {
1313
const seenItems = new Set<string>();
1414
const inheritedMembers = parent.findMembersWithInheritance().items.reduce((acc, item) => {
@@ -25,14 +25,17 @@ export function resolveMembers<T extends ApiItem>(
2525
}
2626

2727
return acc;
28-
}, new Array<{ inherited?: ApiItemContainerMixin | undefined; item: T }>());
28+
}, new Array<{ inherited?: ApiItemContainerMixin | undefined; item: WantedItem }>());
2929

3030
const mergedMembers = parent
3131
.getMergedSiblings()
3232
.filter((sibling) => sibling.containerKey !== parent.containerKey)
3333
.flatMap((sibling) => (sibling as ApiItemContainerMixin).findMembersWithInheritance().items)
3434
.filter((item) => predicate(item) && !seenItems.has(item.containerKey))
35-
.map((item) => ({ item: item as T, inherited: item.parent ? (item.parent as ApiItemContainerMixin) : undefined }));
35+
.map((item) => ({
36+
item: item as WantedItem,
37+
inherited: item.parent ? (item.parent as ApiItemContainerMixin) : undefined,
38+
}));
3639

3740
return [...inheritedMembers, ...mergedMembers];
3841
}

eslint.config.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,17 @@ const typeScriptRuleset = merge(...typescript, {
2525
},
2626
rules: {
2727
'@typescript-eslint/consistent-type-definitions': [2, 'interface'],
28+
'@typescript-eslint/naming-convention': [
29+
2,
30+
{
31+
selector: 'typeParameter',
32+
format: ['PascalCase'],
33+
custom: {
34+
regex: '^\\w{3,}',
35+
match: true,
36+
},
37+
},
38+
],
2839
},
2940
settings: {
3041
'import/resolver': {
@@ -110,6 +121,10 @@ export default [
110121
'@typescript-eslint/no-this-alias': 0,
111122
},
112123
},
124+
{
125+
files: [`packages/{api-extractor,api-extractor-model,api-extractor-utils}/**/*${commonFiles}`],
126+
rules: { '@typescript-eslint/naming-convention': 0 },
127+
},
113128
reactRuleset,
114129
nextRuleset,
115130
edgeRuleset,

packages/brokers/src/brokers/Broker.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export interface IPubSubBroker<TEvents extends Record<string, any>>
7575
/**
7676
* Publishes an event
7777
*/
78-
publish<T extends keyof TEvents>(event: T, data: TEvents[T]): Promise<void>;
78+
publish<Event extends keyof TEvents>(event: Event, data: TEvents[Event]): Promise<void>;
7979
}
8080

8181
export interface IRPCBroker<TEvents extends Record<string, any>, TResponses extends Record<keyof TEvents, any>>
@@ -84,5 +84,9 @@ export interface IRPCBroker<TEvents extends Record<string, any>, TResponses exte
8484
/**
8585
* Makes an RPC call
8686
*/
87-
call<T extends keyof TEvents>(event: T, data: TEvents[T], timeoutDuration?: number): Promise<TResponses[T]>;
87+
call<Event extends keyof TEvents>(
88+
event: Event,
89+
data: TEvents[Event],
90+
timeoutDuration?: number,
91+
): Promise<TResponses[Event]>;
8892
}

packages/brokers/src/brokers/redis/PubSubRedis.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export class PubSubRedisBroker<TEvents extends Record<string, any>>
3636
/**
3737
* {@inheritDoc IPubSubBroker.publish}
3838
*/
39-
public async publish<T extends keyof TEvents>(event: T, data: TEvents[T]): Promise<void> {
39+
public async publish<Event extends keyof TEvents>(event: Event, data: TEvents[Event]): Promise<void> {
4040
await this.options.redisClient.xadd(
4141
event as string,
4242
'*',

packages/brokers/src/brokers/redis/RPCRedis.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,11 @@ export class RPCRedisBroker<TEvents extends Record<string, any>, TResponses exte
8383
/**
8484
* {@inheritDoc IRPCBroker.call}
8585
*/
86-
public async call<T extends keyof TEvents>(
87-
event: T,
88-
data: TEvents[T],
86+
public async call<Event extends keyof TEvents>(
87+
event: Event,
88+
data: TEvents[Event],
8989
timeoutDuration: number = this.options.timeout,
90-
): Promise<TResponses[T]> {
90+
): Promise<TResponses[Event]> {
9191
const id = await this.options.redisClient.xadd(
9292
event as string,
9393
'*',
@@ -103,7 +103,7 @@ export class RPCRedisBroker<TEvents extends Record<string, any>, TResponses exte
103103
const timedOut = new Error(`timed out after ${timeoutDuration}ms`);
104104

105105
await this.streamReadClient.subscribe(rpcChannel);
106-
return new Promise<TResponses[T]>((resolve, reject) => {
106+
return new Promise<TResponses[Event]>((resolve, reject) => {
107107
const timeout = setTimeout(() => reject(timedOut), timeoutDuration).unref();
108108

109109
this.promises.set(id!, { resolve, reject, timeout });

packages/builders/src/components/ActionRow.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,15 @@ export type AnyComponentBuilder = MessageActionRowComponentBuilder | ModalAction
5454
/**
5555
* A builder that creates API-compatible JSON data for action rows.
5656
*
57-
* @typeParam T - The types of components this action row holds
57+
* @typeParam ComponentType - The types of components this action row holds
5858
*/
59-
export class ActionRowBuilder<T extends AnyComponentBuilder> extends ComponentBuilder<
59+
export class ActionRowBuilder<ComponentType extends AnyComponentBuilder> extends ComponentBuilder<
6060
APIActionRowComponent<APIMessageActionRowComponent | APIModalActionRowComponent>
6161
> {
6262
/**
6363
* The components within this action row.
6464
*/
65-
public readonly components: T[];
65+
public readonly components: ComponentType[];
6666

6767
/**
6868
* Creates a new action row from API data.
@@ -100,15 +100,15 @@ export class ActionRowBuilder<T extends AnyComponentBuilder> extends ComponentBu
100100
*/
101101
public constructor({ components, ...data }: Partial<APIActionRowComponent<APIActionRowComponentTypes>> = {}) {
102102
super({ type: ComponentType.ActionRow, ...data });
103-
this.components = (components?.map((component) => createComponentBuilder(component)) ?? []) as T[];
103+
this.components = (components?.map((component) => createComponentBuilder(component)) ?? []) as ComponentType[];
104104
}
105105

106106
/**
107107
* Adds components to this action row.
108108
*
109109
* @param components - The components to add
110110
*/
111-
public addComponents(...components: RestOrArray<T>) {
111+
public addComponents(...components: RestOrArray<ComponentType>) {
112112
this.components.push(...normalizeArray(components));
113113
return this;
114114
}
@@ -118,18 +118,18 @@ export class ActionRowBuilder<T extends AnyComponentBuilder> extends ComponentBu
118118
*
119119
* @param components - The components to set
120120
*/
121-
public setComponents(...components: RestOrArray<T>) {
121+
public setComponents(...components: RestOrArray<ComponentType>) {
122122
this.components.splice(0, this.components.length, ...normalizeArray(components));
123123
return this;
124124
}
125125

126126
/**
127127
* {@inheritDoc ComponentBuilder.toJSON}
128128
*/
129-
public toJSON(): APIActionRowComponent<ReturnType<T['toJSON']>> {
129+
public toJSON(): APIActionRowComponent<ReturnType<ComponentType['toJSON']>> {
130130
return {
131131
...this.data,
132132
components: this.components.map((component) => component.toJSON()),
133-
} as APIActionRowComponent<ReturnType<T['toJSON']>>;
133+
} as APIActionRowComponent<ReturnType<ComponentType['toJSON']>>;
134134
}
135135
}

packages/builders/src/components/Components.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,21 +55,23 @@ export interface MappedComponentTypes {
5555
/**
5656
* Factory for creating components from API data.
5757
*
58-
* @typeParam T - The type of component to use
58+
* @typeParam ComponentType - The type of component to use
5959
* @param data - The API data to transform to a component class
6060
*/
61-
export function createComponentBuilder<T extends keyof MappedComponentTypes>(
61+
export function createComponentBuilder<ComponentType extends keyof MappedComponentTypes>(
6262
// eslint-disable-next-line @typescript-eslint/sort-type-constituents
63-
data: (APIModalComponent | APIMessageComponent) & { type: T },
64-
): MappedComponentTypes[T];
63+
data: (APIModalComponent | APIMessageComponent) & { type: ComponentType },
64+
): MappedComponentTypes[ComponentType];
6565

6666
/**
6767
* Factory for creating components from API data.
6868
*
69-
* @typeParam C - The type of component to use
69+
* @typeParam ComponentBuilder - The type of component to use
7070
* @param data - The API data to transform to a component class
7171
*/
72-
export function createComponentBuilder<C extends MessageComponentBuilder | ModalComponentBuilder>(data: C): C;
72+
export function createComponentBuilder<ComponentBuilder extends MessageComponentBuilder | ModalComponentBuilder>(
73+
data: ComponentBuilder,
74+
): ComponentBuilder;
7375

7476
export function createComponentBuilder(
7577
data: APIMessageComponent | APIModalComponent | MessageComponentBuilder,

packages/builders/src/interactions/slashCommands/Assertions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ export function validateChoicesLength(amountAdding: number, choices?: APIApplica
6666
}
6767

6868
export function assertReturnOfBuilder<
69-
T extends ApplicationCommandOptionBase | SlashCommandSubcommandBuilder | SlashCommandSubcommandGroupBuilder,
70-
>(input: unknown, ExpectedInstanceOf: new () => T): asserts input is T {
69+
ReturnType extends ApplicationCommandOptionBase | SlashCommandSubcommandBuilder | SlashCommandSubcommandGroupBuilder,
70+
>(input: unknown, ExpectedInstanceOf: new () => ReturnType): asserts input is ReturnType {
7171
s.instance(ExpectedInstanceOf).parse(input);
7272
}
7373

packages/builders/src/interactions/slashCommands/mixins/ApplicationCommandOptionWithChoicesAndAutocompleteMixin.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ const booleanPredicate = s.boolean;
1414
/**
1515
* This mixin holds choices and autocomplete symbols used for options.
1616
*/
17-
export class ApplicationCommandOptionWithChoicesAndAutocompleteMixin<T extends number | string> {
17+
export class ApplicationCommandOptionWithChoicesAndAutocompleteMixin<ChoiceType extends number | string> {
1818
/**
1919
* The choices of this option.
2020
*/
21-
public readonly choices?: APIApplicationCommandOptionChoice<T>[];
21+
public readonly choices?: APIApplicationCommandOptionChoice<ChoiceType>[];
2222

2323
/**
2424
* Whether this option utilizes autocomplete.
@@ -37,7 +37,7 @@ export class ApplicationCommandOptionWithChoicesAndAutocompleteMixin<T extends n
3737
*
3838
* @param choices - The choices to add
3939
*/
40-
public addChoices(...choices: APIApplicationCommandOptionChoice<T>[]): this {
40+
public addChoices(...choices: APIApplicationCommandOptionChoice<ChoiceType>[]): this {
4141
if (choices.length > 0 && this.autocomplete) {
4242
throw new RangeError('Autocomplete and choices are mutually exclusive to each other.');
4343
}
@@ -69,7 +69,7 @@ export class ApplicationCommandOptionWithChoicesAndAutocompleteMixin<T extends n
6969
*
7070
* @param choices - The choices to set
7171
*/
72-
public setChoices<Input extends APIApplicationCommandOptionChoice<T>[]>(...choices: Input): this {
72+
public setChoices<Input extends APIApplicationCommandOptionChoice<ChoiceType>[]>(...choices: Input): this {
7373
if (choices.length > 0 && this.autocomplete) {
7474
throw new RangeError('Autocomplete and choices are mutually exclusive to each other.');
7575
}

packages/builders/src/interactions/slashCommands/mixins/SharedSlashCommandOptions.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,15 @@ export class SharedSlashCommandOptions<ShouldOmitSubcommandFunctions = true> {
148148
* @param Instance - The instance of whatever is being added
149149
* @internal
150150
*/
151-
private _sharedAddOptionMethod<T extends ApplicationCommandOptionBase>(
151+
private _sharedAddOptionMethod<OptionBuilder extends ApplicationCommandOptionBase>(
152152
input:
153-
| Omit<T, 'addChoices'>
154-
| Omit<T, 'setAutocomplete'>
155-
| T
156-
| ((builder: T) => Omit<T, 'addChoices'> | Omit<T, 'setAutocomplete'> | T),
157-
Instance: new () => T,
153+
| Omit<OptionBuilder, 'addChoices'>
154+
| Omit<OptionBuilder, 'setAutocomplete'>
155+
| OptionBuilder
156+
| ((
157+
builder: OptionBuilder,
158+
) => Omit<OptionBuilder, 'addChoices'> | Omit<OptionBuilder, 'setAutocomplete'> | OptionBuilder),
159+
Instance: new () => OptionBuilder,
158160
): ShouldOmitSubcommandFunctions extends true ? Omit<this, 'addSubcommand' | 'addSubcommandGroup'> : this {
159161
const { options } = this;
160162

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/**
22
* Normalizes data that is a rest parameter or an array into an array with a depth of 1.
33
*
4-
* @typeParam T - The data that must satisfy {@link RestOrArray}.
4+
* @typeParam ItemType - The data that must satisfy {@link RestOrArray}.
55
* @param arr - The (possibly variadic) data to normalize
66
*/
7-
export function normalizeArray<T>(arr: RestOrArray<T>): T[] {
7+
export function normalizeArray<ItemType>(arr: RestOrArray<ItemType>): ItemType[] {
88
if (Array.isArray(arr[0])) return arr[0];
9-
return arr as T[];
9+
return arr as ItemType[];
1010
}
1111

1212
/**
@@ -16,4 +16,4 @@ export function normalizeArray<T>(arr: RestOrArray<T>): T[] {
1616
* This type is used throughout builders to ensure both an array and variadic arguments
1717
* may be used. It is normalized with {@link normalizeArray}.
1818
*/
19-
export type RestOrArray<T> = T[] | [T[]];
19+
export type RestOrArray<Type> = Type[] | [Type[]];

packages/collection/__tests__/collection.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
import { describe, test, expect } from 'vitest';
44
import { Collection } from '../src/index.js';
55

6-
type TestCollection<V> = Collection<string, V>;
6+
type TestCollection<Value> = Collection<string, Value>;
77

8-
function createCollection<V = number>(): TestCollection<V> {
8+
function createCollection<Value = number>(): TestCollection<Value> {
99
return new Collection();
1010
}
1111

12-
function createCollectionFrom<V = number>(...entries: [key: string, value: V][]): TestCollection<V> {
12+
function createCollectionFrom<Value = number>(...entries: [key: string, value: Value][]): TestCollection<Value> {
1313
return new Collection(entries);
1414
}
1515

0 commit comments

Comments
 (0)