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 type definitions #13

Open
andrewvasilchuk opened this issue Nov 13, 2019 · 5 comments
Open

Add type definitions #13

andrewvasilchuk opened this issue Nov 13, 2019 · 5 comments

Comments

@andrewvasilchuk
Copy link

andrewvasilchuk commented Nov 13, 2019

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

@archaeron
Copy link

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";

@IagoLast
Copy link

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

@archaeron
Copy link

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

@IagoLast
Copy link

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

@archaeron
Copy link

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

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

No branches or pull requests

3 participants