sapphiredev/framework

request: use `declare`

BrianWasTaken opened this issue · 2 comments

Is there an existing issue or pull request for this?

  • 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

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

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.