Skip to content

cooldown or globalCooldown, not both#31

Open
k-tten wants to merge 2 commits into
AlexzanderFlores:mainfrom
k-tten:patch-2
Open

cooldown or globalCooldown, not both#31
k-tten wants to merge 2 commits into
AlexzanderFlores:mainfrom
k-tten:patch-2

Conversation

@k-tten
Copy link
Copy Markdown
Contributor

@k-tten k-tten commented Feb 17, 2021

With this interface hierarchy, TypeScript enforces that you can have cooldown or globalCooldown, but not both.

With this interface hierarchy, TypeScript enforces that you can have cooldown or globalCooldown, but not both.
@mcdaddytalk
Copy link
Copy Markdown

mcdaddytalk commented May 6, 2022

One modification, otherwise, the code does not type properly and throws an error:
To union the two Base interfaces to the ICommand interface it is better to use:

interface BaseCommandWithCooldown extends BaseCommand {
    cooldown?: string;
    globalCooldown?: never;
}

interface BaseCommandWithGlobalCooldown extends BaseCommand {
    cooldown?: never;
    globalCooldown?: string;
}

export type ICommand = BaseCommandWithCooldown | BaseCommandWithGlobalCooldown;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants