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

(enhancement) Create typescript type definitons #102

Open
dheerajbhaskar opened this issue Jun 14, 2018 · 6 comments
Open

(enhancement) Create typescript type definitons #102

dheerajbhaskar opened this issue Jun 14, 2018 · 6 comments
Labels

Comments

@dheerajbhaskar
Copy link

@dheerajbhaskar dheerajbhaskar commented Jun 14, 2018

Purpose:

Create Typescript type definitions

  • So that I can do npm i @types/watchr

Backgorund:

I believe there is some flow type information, can you please re-purpose that for typescript so one can get intellisense.

Note: If you can guide me on how to do that, I might be able to pull it off as well

@dheerajbhaskar dheerajbhaskar changed the title (enhancement) Create typescript types (enhancement) Create typescript type definitons Jun 14, 2018
@dheerajbhaskar

This comment has been minimized.

Copy link
Author

@dheerajbhaskar dheerajbhaskar commented Jun 14, 2018

Following are the types I found in the package sources. Can anyone help me how do I create typescript defs from this and then how do I submit that definitelyTyped or elsewhere or so that the purpose of this issue is fulfilled?

/* ::
import type {Stats, FSWatcher} from 'fs'
type StateEnum = "pending" | "active" | "deleted" | "closed"
type MethodEnum = "watch" | "watchFile"
type ErrorCallback = (error: ?Error) => void
type StatCallback = (error: ?Error, stat?: Stats) => void
type WatchChildOpts = {
	fullPath: string,
	relativePath: string,
	stat?: Stats
}
type WatchSelfOpts = {
	errors?: Array<Error>,
	preferredMethods?: Array<MethodEnum>
}
type ListenerOpts = {
	method: MethodEnum,
	args: Array<any>
}
type ResetOpts = {
	reset?: boolean
}
type IgnoreOpts = {
	ignorePaths?: boolean,
	ignoreHiddenFiles?: boolean,
	ignoreCommonPatterns?: boolean,
	ignoreCustomPatterns?: RegExp
}
type WatcherOpts = IgnoreOpts & {
	stat?: Stats,
	interval?: number,
	persistent?: boolean,
	catchupDelay?: number,
	preferredMethods?: Array<MethodEnum>,
	followLinks?: boolean
}
type WatcherConfig = {
	stat: ?Stats,
	interval: number,
	persistent: boolean,
	catchupDelay: number,
	preferredMethods: Array<MethodEnum>,
	followLinks: boolean,
	ignorePaths: false | Array<string>,
	ignoreHiddenFiles: boolean,
	ignoreCommonPatterns: boolean,
	ignoreCustomPatterns: ?RegExp
}
*/
@balupton

This comment has been minimized.

Copy link
Member

@balupton balupton commented Jul 24, 2018

I wouldn’t know, as I don’t use typescript

@balupton

This comment has been minimized.

Copy link
Member

@balupton balupton commented Aug 19, 2018

Ok. If anyone wants to tackle this, it would be via the movement from the flowtype comments to the typescript jsdoc comments.

Did the migration for https://github.com/bevry/caterpillar earlier this week:
bevry/caterpillar@f2486e3

@jbreckmckye

This comment has been minimized.

Copy link

@jbreckmckye jbreckmckye commented Nov 22, 2018

Does this look right?

/// <reference types="node" />

declare module 'watchr' {
    import {Stats, FSWatcher} from 'fs';
    import {EventEmitter} from 'events';

    export type ChangeType = 'update' | 'create' | 'delete';

    export type State = 'pending' | 'active' | 'deleted' | 'closed';

    export type Method = 'watch' | 'watchFile';

    export type ErrorCallback = (error?: Error) => void;

    export type StatCallback = (error?: Error, stat?: Stats) => void;

    export type ChangeListener = (changeType: ChangeType, fullPath: string, currentStat: Stats, prevStat: Stats) => void;

    export interface ResetOpts {
        reset?: boolean
    }

    export interface IgnoreOpts {
        ignorePaths?: boolean,
        ignoreHiddenFiles?: boolean,
        ignoreCommonPatterns?: boolean,
        ignoreCustomPatterns?: RegExp
    }

    export type WatcherOpts = IgnoreOpts & {
        stat?: Stats,
        interval?: number,
        persistent?: boolean,
        catchupDelay?: number,
        preferredMethods?: Method[],
        followLinks?: boolean
    }

    export interface WatcherConfig {
        stat?: Stats,
        interval: number,
        persistent: boolean,
        catchupDelay: number,
        preferredMethods: Method[],
        followLinks: boolean,
        ignorePaths: false | Array<string>,
        ignoreHiddenFiles: boolean,
        ignoreCommonPatterns: boolean,
        ignoreCustomPatterns?: RegExp
    }

    export class Stalker extends EventEmitter {
        watcher: Watcher;
        watchers: {[key: string]: Watcher};

        close(reason: string): Stalker;

        setConfig(...args: any[]): Stalker;

        watch(...args: any[]): Stalker;
    }

    export class Watcher extends EventEmitter {
        stalkers: Stalker[];
        path: string;
        stat: Stats;
        fswatcher: FSWatcher;
        children: {[key: string]: Stalker};
        state: State;
        listenerTaskGroup: any;
        listenerTimeout: number;
        config: WatcherConfig;

        setConfig(opts: WatcherOpts): Watcher;

        log(...args: any[]): Watcher;

        getStat(opts: ResetOpts, next: StatCallback): Watcher;

        close(reason?: string): Watcher;

        watch(next: Function): Watcher;
        watch(opts: ResetOpts, next: Function): Watcher;
    }

    export function open(path: string, changeListener: ChangeListener, next: ErrorCallback): Stalker;

    export function create(...args: any[]): Stalker;
}
@balupton

This comment has been minimized.

Copy link
Member

@balupton balupton commented Nov 26, 2018

I'm not sure all the event properties are available on every event. I think old and new stats are dependent on the event type. So a generic may be needed or multiple function signatures.

I am planning to move all edited projects to typescript. If I setup this project with our typescript conventions, will anyone here want to finalise the conversion?

If so, I'll get the foundations done on a new branch and hand it over for forking.

Details on our conversion plan is found here:
https://discuss.bevry.me/t/typescript-conversions-for-bevry-packages/269?u=balupton

@balupton

This comment has been minimized.

Copy link
Member

@balupton balupton commented Dec 7, 2018

To convert this project to TypeScript:

  1. clone watchr
  2. create a dev-typescript branch
  3. run https://github.com/bevry/boundation on it, changing the language from esnext to typescript
  4. perform the manual conversion, fix all typescript errors
  5. run boundation again
  6. send a PR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.