activity-detector icon indicating copy to clipboard operation
activity-detector copied to clipboard

Add type definitions

Open andrewvasilchuk opened this issue 5 years ago • 5 comments

@atabel, It would be great if you can add support for type definitions.

andrewvasilchuk avatar Nov 13 '19 07:11 andrewvasilchuk

this seems to work for me:

declare module "activity-detector" {
  export type ActivityState = "idle" | "active";

  export type ActivityDetectorOptions = {
    /**
     * Events which force a transition to 'active'
     *
     * Default:
     *  [ 'click', 'mousemove', 'keydown', 'DOMMouseScroll',
     *    'mousewheel', 'mousedown', 'touchstart', 'touchmove',
     *    'focus' ];
     */
    activityEvents?: Array<string>;
    /**
     * Events which force a transition to 'idle'
     *
     * Default: ['blur', 'visibilitychange']
     */
    inactivityEvents?: Array<string>;
    /**
     * Events that are ignored in 'idle' state
     *
     * Default: ['mousemove']
     */
    ignoredEventsWhenIdle?: Array<string>;
    /**
     *  Inactivity time in ms to transition to 'idle'
     */
    timeToIdle?: number;
    initialState?: ActivityState;
    autoInit?: boolean;
  };

  export type ActivityDetectorInstance = {
    on: (eventName: ActivityState, listener: () => void) => void;
    stop: () => void;
    init: (firstState: ActivityState) => {};
  };

  function createActivityDetector(
    options: ActivityDetectorOptions
  ): ActivityDetectorInstance;
  export default createActivityDetector;
}

you should then be able to use it like this:

import createActivityDetector, { ActivityDetectorOptions } from "activity-detector";

archaeron avatar May 20 '20 09:05 archaeron

Nice @archaeron, you should submit a PR with that to https://github.com/DefinitelyTyped/DefinitelyTyped

IagoLast avatar Feb 15 '21 08:02 IagoLast

I'm not using this anymore. This was at an other job.

archaeron avatar Feb 16 '21 15:02 archaeron

@archaeron but the thing is still open source and that types will help another devs...

IagoLast avatar Feb 16 '21 15:02 IagoLast

I understand, but I don't even have a project anymore to test this out. But I'm happy for someone else to use the code

archaeron avatar Feb 16 '21 15:02 archaeron