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

Add typescript typings #4

Open
devmondo opened this issue Jun 4, 2019 · 3 comments · May be fixed by #25
Open

Add typescript typings #4

devmondo opened this issue Jun 4, 2019 · 3 comments · May be fixed by #25
Assignees
Labels
feature New feature or request
Milestone

Comments

@devmondo
Copy link

devmondo commented Jun 4, 2019

hi,

it would be great if we have typings so we get IntelliSense in IDE and stop typescript complaining.

@jbcarpanelli jbcarpanelli added the feature New feature or request label Jun 4, 2019
@jbcarpanelli jbcarpanelli added this to the v0.4.0 milestone Jun 5, 2019
@cfanoulis
Copy link

Hello! Any status on this?

adamjarret added a commit to adamjarret/spinnies that referenced this issue May 1, 2020
@adamjarret adamjarret linked a pull request May 1, 2020 that will close this issue
@reslear
Copy link

reslear commented Aug 13, 2020

or use Spinnies.d.ts based on @adamjarret #25

declare module "spinnies" {
  type StopAllStatus = "succeed" | "fail" | "stopped";
  type SpinnerStatus = StopAllStatus | "spinning" | "non-spinnable";

  interface Spinner {
    interval: number;
    frames: string[];
  }

  interface SpinnerOptions {
    text?: string;
    indent?: number;
    status?: SpinnerStatus;
    color?: string;
    succeedColor?: string;
    failColor?: string;
  }

  interface Options {
    color?: string;
    succeedColor?: string;
    failColor?: string;
    spinnerColor?: string;
    succeedPrefix?: string;
    failPrefix?: string;
    disableSpins?: boolean;
    spinner?: Spinner;
  }

  export default class Spinnies {
    static dots: Spinner;
    static dashes: Spinner;
    constructor(options?: Options);
    add: (name: string, options?: SpinnerOptions) => SpinnerOptions;
    pick: (name: string) => SpinnerOptions;
    remove: (name: string) => SpinnerOptions;
    update: (name: string, options?: SpinnerOptions) => SpinnerOptions;
    succeed: (name: string, options?: SpinnerOptions) => SpinnerOptions;
    fail: (name: string, options?: SpinnerOptions) => SpinnerOptions;
    stopAll: (status?: StopAllStatus) => { [name: string]: SpinnerOptions };
    hasActiveSpinners: () => boolean;
  }
}

@benjamincburns
Copy link

I'm hoping to get types added to DefinitelyTyped over in DefinitelyTyped/DefinitelyTyped#59503. In the meantime, here is the slightly improved local type declarations file that I'm using in my project:

declare module "spinnies" {
  const dots: Spinner;
  const dashes: Spinner;

  type Color =
    "black"
    | "red"
    | "green"
    | "yellow"
    | "blue"
    | "magenta"
    | "cyan"
    | "white"
    | "gray"
    | "redBright"
    | "greenBright"
    | "yellowBright"
    | "blueBright"
    | "magentaBright"
    | "cyanBright"
    | "whiteBright";

  type StopAllStatus = "succeed" | "fail" | "stopped";
  type SpinnerStatus = StopAllStatus | "spinning" | "non-spinnable";

  interface Spinner {
    interval: number;
    frames: string[];
  }

  /**
   * The configuration for a given spinner
   */
  interface SpinnerOptions {
    /**
     * Text to show in the spinner. If none is provided, the name field will be shown.
     */
    text: string;

    /**
     * Indent the spinner with the given number of spaces.
     */
    indent: number;

    /**
     * Initial status of the spinner.
     */
    status: SpinnerStatus;

    /**
     * The color of the text that accompanies the spinner. If not specified, the console's default foreground color is used.
     */
    color?: Color;

    /**
     * The color for the text on success. Default value is `"green"`
     */
    succeedColor: Color;

    /**
     * The color for the text on failure. Default value is `"red"`.
     */
    failColor: Color;

    /**
     * The color of the spinner, when active. The default value is `"greenBright"`
     */
    spinnerColor: Color;
  }

  /**
   * Contains top-level configuration for the Spinnies class. Also allows the
   * caller to override default values used in `SpinnerOptions`.
   */
  interface Options {
    /**
     * The color of the text that accompanies the spinner. If not specified, the console's default foreground color is used.
     */
    color?: Color;

    /**
     * The color for the text on success. Default value is `"green"`
     */
    succeedColor: Color;

    /**
     * The color for the text on failure. Default value is `"red"`.
     */
    failColor: Color;

    /**
     * The color of the spinner, when active. The default value is `"greenBright"`
     */
    spinnerColor: Color;

    /**
     * The symbol to be used in place of the spinner on success. The default value is ✓.
     */
    succeedPrefix: string;

    /**
     * The symbol to be used in place of the spinner on failure. The default value is ✖.
     */
    failPrefix: string;

    /**
     * Disable spinner animations (will still print raw messages if `true`). The default value is `false`.
     */
    disableSpins: boolean;

    /**
     * Defines the animated spinner to be used while each spinner is active/spinning.
     */
    spinner: Spinner;
  }

  /**
   * A class that manages multiple CLI spinners.
   */
  export default class Spinnies {
    /**
     * The current configuration of this Spinnies object.
     */
    options: Spinnies.Options;

    constructor(options?: Partial<Spinnies.Options>);

    /**
     * Add a new spinner with the given name.
     *
     * @returns full `SpinnerOptions` object for the given spinner, with
     * defaults applied
     */
    add: (name: string, options?: Partial<Spinnies.SpinnerOptions>) => Spinnies.SpinnerOptions;

    /**
     * Get spinner by name.
     *
     * @returns full `SpinnerOptions` object for the given spinner, with
     * defaults applied
     */
    pick: (name: string) => Spinnies.SpinnerOptions;

    /**
     * Remove spinner with name.
     *
     * @returns full `SpinnerOptions` object for the given spinner, with
     * defaults applied
     */
    remove: (name: string) => Spinnies.SpinnerOptions;

    /**
     * Updates the spinner with name name with the provided options. Retains
     * the value of options that aren't specified.
     *
     * @returns full `SpinnerOptions` object for the given spinner, with
     * defaults applied
     */
    update: (name: string, options?: Partial<Spinnies.SpinnerOptions>) => Spinnies.SpinnerOptions;

    /**
     * Sets the specified spinner status as succeed.
     *
     * @returns full `SpinnerOptions` object for the given spinner, with
     * defaults applied
     */
    succeed: (name: string, options?: Partial<Spinnies.SpinnerOptions>) => Spinnies.SpinnerOptions;

    /**
     * Sets the specified spinner status as fail.
     *
     * @returns full `SpinnerOptions` object for the given spinner, with
     * defaults applied
     */
    fail: (name: string, options?: Partial<Spinnies.SpinnerOptions>) => Spinnies.SpinnerOptions;

    /**
     * Stops the spinners and sets the non-succeeded and non-failed ones to the provided status.
     *
     * @returns an object that maps spinner names to final `SpinnerOptions` objects for each spinner, with
     * defaults applied
     */
    stopAll: (status?: Spinnies.StopAllStatus) => { [name: string]: Spinnies.SpinnerOptions };

    /**
     * @returns false if all spinners have succeeded, failed or have been stopped
     */
    hasActiveSpinners: () => boolean;

    /**
     * Disables the spinner loop after all spinners have deactivated. Must be
     * called after calling `remove` on the final spinner, otherwise the
     * spinner loop will prevent the process from exiting.
     */
    checkIfActiveSpinners: () => void;
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants