framework icon indicating copy to clipboard operation
framework copied to clipboard

request: use `declare`

Open BrianWasTaken opened this issue 3 years ago • 2 comments

Is there an existing issue or pull request for this?

  • [X] I have searched the existing issues and pull requests

Feature description

A "problem" with overridable types. This one is just my personal solution to have accurate types wherever possible.

Command#piece appears to be Store<Piece<PieceOptions>> still when it should be CommandStore instead.

Desired solution

Ever considered using the declare modifier for class properties? Not much of a big deal anyway since the developer could just assert it to a specific store type but IMO it's helpful since it offers a shorter way of accessing the store that holds the piece.

Example:

// Command.ts
export class Command extends Piece {
  public declare store: CommandStore;
}
// help.ts
export default class extends Command {
  public override messageRun(message: Message) {
    const commands = [...this.store.values()]; // Command<Args, CommandOptions>[]
    console.log(commands.map(c => c.name));
  }
} 

Alternatives considered

Use the common way of obtaining a store.

container.stores.get('store');

Additional context

No response

BrianWasTaken avatar Feb 18 '22 10:02 BrianWasTaken

Why do we need this? It just seems more complicated.

devramsean0 avatar Feb 22 '22 16:02 devramsean0

Why do we need this? It just seems more complicated.

It's not. This overrides the types from the parent class to the inherited one. It just doesn't look right if you access the command store inside a command as Store<AliasPiece<PieceOptions>> when it should be CommandStore instead.

BrianWasTaken avatar Feb 26 '22 07:02 BrianWasTaken