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

Typescript module definitions #44

Open
lukasolson opened this issue Feb 7, 2020 · 6 comments
Open

Typescript module definitions #44

lukasolson opened this issue Feb 7, 2020 · 6 comments

Comments

@lukasolson
Copy link

I'm trying to use this in a Typescript project, but am having to in an odd way because this library doesn't have type module definitions. Any plans to add this? I'm happy to spin up a PR if it's helpful.

@mo
Copy link
Owner

mo commented Feb 8, 2020

I don't think anyone has created TS definitions yet, a PR would be great

@mo
Copy link
Owner

mo commented Feb 11, 2020

What approach are you planning; rewrite in TS and generate .d.ts files on build, or manually writing the .d.ts files?

@mo
Copy link
Owner

mo commented Feb 11, 2020

FWIW, I pushed the commit "e9880c8" to master now, it upgrades all dependencies to the latest versions and re-pins chromedriver/geckodriver to fresh versions. To run the tests you must have chrome v80 installed and then just do "npm test". The firefox tests are a bit more flexible in terms on version, you can run them using "npm run test-firefox".

@xamgore
Copy link

xamgore commented Dec 3, 2020

I do believe the following typings can be used:

declare module 'abortcontroller-polyfill/dist/cjs-ponyfill' {
  /** A controller object that allows you to abort one or more DOM requests as and when desired. */
  interface AbortController {
    /**
     * Returns the AbortSignal object associated with this object.
     */
    readonly signal: AbortSignal

    /**
     * Invoking this method will set this object's AbortSignal's aborted flag and signal to any observers that the associated activity is to be aborted.
     */
    abort(): void
  }

  const AbortController: {
    prototype: AbortController
    new(): AbortController
  }

  interface AbortSignalEventMap {
    'abort': Event
  }

  /** A signal object that allows you to communicate with a DOM request (such as a Fetch) and abort it if required via an AbortController object. */
  interface AbortSignal extends EventTarget {
    /**
     * Returns true if this AbortSignal's AbortController has signaled to abort, and false otherwise.
     */
    readonly aborted: boolean
    onabort: ((this: AbortSignal, ev: Event) => any) | null

    addEventListener<K extends keyof AbortSignalEventMap>(type: K, listener: (this: AbortSignal, ev: AbortSignalEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void

    addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void

    removeEventListener<K extends keyof AbortSignalEventMap>(type: K, listener: (this: AbortSignal, ev: AbortSignalEventMap[K]) => any, options?: boolean | EventListenerOptions): void

    removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void
  }

  const AbortSignal: {
    prototype: AbortSignal
    new(): AbortSignal
  }
}

@ghost
Copy link

ghost commented Jul 11, 2022

@mo Could you add the above code to .d.ts file please?

@TechQuery
Copy link

TypeScript has fixed this issue in latest version: microsoft/TypeScript#51567

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

4 participants