Skip to content

Commit b243bcd

Browse files
authoredFeb 5, 2023
fix: use declare for store properties to avoid the need for as *Store (#602)
This ensures that people no longer need to write code such as `const commandsStore = this.store as CommandStore` but instead can keep out the typecast. resolves #382
1 parent b4c252e commit b243bcd

File tree

5 files changed

+30
-1
lines changed

5 files changed

+30
-1
lines changed
 

‎src/lib/structures/Argument.ts

+6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type { Awaitable } from '@sapphire/utilities';
44
import type { Message } from 'discord.js';
55
import type { ArgumentError } from '../errors/ArgumentError';
66
import { Args } from '../parsers/Args';
7+
import type { ArgumentStore } from './ArgumentStore';
78
import type { MessageCommand } from './Command';
89

910
/**
@@ -102,6 +103,11 @@ export interface IArgument<T> {
102103
* ```
103104
*/
104105
export abstract class Argument<T = unknown, O extends Argument.Options = Argument.Options> extends AliasPiece<O> implements IArgument<T> {
106+
/**
107+
* The {@link ArgumentStore} that contains this {@link Argument}.
108+
*/
109+
public declare store: ArgumentStore;
110+
105111
public abstract run(parameter: string, context: Argument.Context<T>): Argument.AwaitableResult<T>;
106112

107113
/**

‎src/lib/structures/Command.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ import { FlagUnorderedStrategy, type FlagStrategyOptions } from '../utils/strate
2121
import type { CommandStore } from './CommandStore';
2222

2323
export class Command<PreParseReturn = Args, O extends Command.Options = Command.Options> extends AliasPiece<O> {
24+
/**
25+
* The {@link CommandStore} that contains this {@link Command}.
26+
*/
27+
public declare store: CommandStore;
28+
2429
/**
2530
* A basic summary about the command
2631
* @since 1.0.0
@@ -249,7 +254,7 @@ export class Command<PreParseReturn = Args, O extends Command.Options = Command.
249254

250255
public override async reload() {
251256
// Remove the aliases from the command store
252-
const store = this.store as CommandStore;
257+
const { store } = this;
253258
const registry = this.applicationCommandRegistry;
254259

255260
for (const nameOrId of registry.chatInputCommands) {

‎src/lib/structures/InteractionHandler.ts

+6
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,14 @@ import { Piece } from '@sapphire/pieces';
22
import { Option } from '@sapphire/result';
33
import type { Awaitable } from '@sapphire/utilities';
44
import type { Interaction } from 'discord.js';
5+
import type { InteractionHandlerStore } from './InteractionHandlerStore';
56

67
export abstract class InteractionHandler<O extends InteractionHandler.Options = InteractionHandler.Options> extends Piece<O> {
8+
/**
9+
* The {@link InteractionHandlerStore} that contains this {@link InteractionHandler}.
10+
*/
11+
public declare store: InteractionHandlerStore;
12+
713
/**
814
* The type for this handler
915
* @since 3.0.0

‎src/lib/structures/Listener.ts

+6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Result } from '@sapphire/result';
33
import type { Client, ClientEvents } from 'discord.js';
44
import type { EventEmitter } from 'node:events';
55
import { Events } from '../types/Events';
6+
import type { ListenerStore } from './ListenerStore';
67

78
/**
89
* The base event class. This class is abstract and is to be extended by subclasses, which should implement the methods. In
@@ -44,6 +45,11 @@ import { Events } from '../types/Events';
4445
* ```
4546
*/
4647
export abstract class Listener<E extends keyof ClientEvents | symbol = '', O extends Listener.Options = Listener.Options> extends Piece<O> {
48+
/**
49+
* The {@link ListenerStore} that contains this {@link Listener}.
50+
*/
51+
public declare store: ListenerStore;
52+
4753
/**
4854
* The emitter, if any.
4955
* @since 2.0.0

‎src/lib/structures/Precondition.ts

+6
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,17 @@ import type { CooldownPreconditionContext } from '../../preconditions/Cooldown';
1313
import { PreconditionError } from '../errors/PreconditionError';
1414
import type { UserError } from '../errors/UserError';
1515
import type { ChatInputCommand, ContextMenuCommand, MessageCommand } from './Command';
16+
import type { PreconditionStore } from './PreconditionStore';
1617

1718
export type PreconditionResult = Awaitable<Result<unknown, UserError>>;
1819
export type AsyncPreconditionResult = Promise<Result<unknown, UserError>>;
1920

2021
export class Precondition<O extends Precondition.Options = Precondition.Options> extends Piece<O> {
22+
/**
23+
* The {@link PreconditionStore} that contains this {@link Precondition}.
24+
*/
25+
public declare store: PreconditionStore;
26+
2127
public readonly position: number | null;
2228

2329
public constructor(context: Piece.Context, options: Precondition.Options = {}) {

0 commit comments

Comments
 (0)
Please sign in to comment.