Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cooldown or globalCooldown, not both #31

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

cooldown or globalCooldown, not both #31

wants to merge 2 commits into from

Conversation

k-tten
Copy link
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

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