index.d.ts 945 B

123456789101112131415161718192021222324
  1. // Type definitions for ngraph.events v1.0.0
  2. // Project: https://github.com/anvaka/ngraph.graph
  3. // Definitions by: Tobias Kopelke <https://github.com/lordnox>
  4. declare module "ngraph.events" {
  5. // define keys that are allowed as event names
  6. export type EventKey = string | number | Symbol
  7. // define basic function that is allowed for event listeners
  8. export type EventCallback = (...args: any[]) => void
  9. // defined additional event properties that will be added by eventify
  10. export interface EventedType {
  11. on: (eventName: EventKey, callback: EventCallback, ctx?: any) => this
  12. off: (eventName?: EventKey, callback?: EventCallback) => this
  13. fire: (eventName: EventKey, ...args: any[]) => this
  14. }
  15. // extend generic object type as Generic but remove the on, off, fire properties
  16. export default function eventify<Type extends {}>(subject: Type & {
  17. on?: never
  18. off?: never
  19. fire?: never
  20. }): EventedType & Type
  21. }