diff --git a/types/react-event-listener/index.d.ts b/types/react-event-listener/index.d.ts index c3ff194394..c264735c08 100644 --- a/types/react-event-listener/index.d.ts +++ b/types/react-event-listener/index.d.ts @@ -4,7 +4,7 @@ // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.8 -import * as React from "react"; +import React = require("react"); export interface EventOptions { /** diff --git a/types/react-event-listener/package.json b/types/react-event-listener/package.json new file mode 100644 index 0000000000..24c89a85ed --- /dev/null +++ b/types/react-event-listener/package.json @@ -0,0 +1,7 @@ +{ + "private": true, + "types": "index", + "typesVersions": { + ">=3.1.0-0": { "*": ["ts3.1/*"] } + } +} \ No newline at end of file diff --git a/types/react-event-listener/react-event-listener-tests.tsx b/types/react-event-listener/react-event-listener-tests.tsx index 8b9aae2c4d..e9a00dcc5f 100644 --- a/types/react-event-listener/react-event-listener-tests.tsx +++ b/types/react-event-listener/react-event-listener-tests.tsx @@ -1,4 +1,4 @@ -import * as React from "react"; +import React = require("react"); import EventListener, { withOptions } from "react-event-listener"; { }} />; diff --git a/types/react-event-listener/ts3.1/index.d.ts b/types/react-event-listener/ts3.1/index.d.ts new file mode 100644 index 0000000000..b6e11bed31 --- /dev/null +++ b/types/react-event-listener/ts3.1/index.d.ts @@ -0,0 +1,220 @@ +import React = require("react"); + +export interface EventOptions extends Pick { } + +export function withOptions(handler: (this: TThis, ev: T) => any, options: EventOptions): (this: TThis, ev: T) => any; + +export type EventListenerThisType = T extends keyof Window ? Window[T] : T; + +export type OnErrorEventHandlerArgs = OnErrorEventHandlerNonNull extends (...args: infer A) => any ? A : []; + +export interface EventListenerProps { + // Global events + onPointerCancel?(this: EventListenerThisType, ev: PointerEvent): any; + onPointerCancelCapture?(this: EventListenerThisType, ev: PointerEvent): any; + onPointerDown?(this: EventListenerThisType, ev: PointerEvent): any; + onPointerDownCapture?(this: EventListenerThisType, ev: PointerEvent): any; + onPointerEnter?(this: EventListenerThisType, ev: PointerEvent): any; + onPointerEnterCapture?(this: EventListenerThisType, ev: PointerEvent): any; + onPointerLeave?(this: EventListenerThisType, ev: PointerEvent): any; + onPointerLeaveCapture?(this: EventListenerThisType, ev: PointerEvent): any; + onPointerMove?(this: EventListenerThisType, ev: PointerEvent): any; + onPointerMoveCapture?(this: EventListenerThisType, ev: PointerEvent): any; + onPointerOut?(this: EventListenerThisType, ev: PointerEvent): any; + onPointerOutCapture?(this: EventListenerThisType, ev: PointerEvent): any; + onPointerOver?(this: EventListenerThisType, ev: PointerEvent): any; + onPointerOverCapture?(this: EventListenerThisType, ev: PointerEvent): any; + onPointerUp?(this: EventListenerThisType, ev: PointerEvent): any; + onPointerUpCapture?(this: EventListenerThisType, ev: PointerEvent): any; + onWheel?(this: EventListenerThisType, ev: WheelEvent): any; + onWheelCapture?(this: EventListenerThisType, ev: WheelEvent): any; + onAbort?(this: EventListenerThisType, ev: Event): any; + onAbortCapture?(this: EventListenerThisType, ev: Event): any; + onAfterPrint?(this: EventListenerThisType, ev: Event): any; + onAfterPrintCapture?(this: EventListenerThisType, ev: Event): any; + onBeforePrint?(this: EventListenerThisType, ev: Event): any; + onBeforePrintCapture?(this: EventListenerThisType, ev: Event): any; + onBeforeUnload?(this: EventListenerThisType, ev: BeforeUnloadEvent): any; + onBeforeUnloadCapture?(this: EventListenerThisType, ev: BeforeUnloadEvent): any; + onBlur?(this: EventListenerThisType, ev: FocusEvent): any; + onBlurCapture?(this: EventListenerThisType, ev: FocusEvent): any; + onCanPlay?(this: EventListenerThisType, ev: Event): any; + onCanPlayCapture?(this: EventListenerThisType, ev: Event): any; + onCanPlayThrough?(this: EventListenerThisType, ev: Event): any; + onCanPlayThroughCapture?(this: EventListenerThisType, ev: Event): any; + onChange?(this: EventListenerThisType, ev: Event): any; + onChangeCapture?(this: EventListenerThisType, ev: Event): any; + onClick?(this: EventListenerThisType, ev: MouseEvent): any; + onClickCapture?(this: EventListenerThisType, ev: MouseEvent): any; + onCompassNeedsCalibration?(this: EventListenerThisType, ev: Event): any; + onCompassNeedsCalibrationCapture?(this: EventListenerThisType, ev: Event): any; + onContextMenu?(this: EventListenerThisType, ev: PointerEvent): any; + onContextMenuCapture?(this: EventListenerThisType, ev: PointerEvent): any; + onDblClick?(this: EventListenerThisType, ev: MouseEvent): any; + onDblClickCapture?(this: EventListenerThisType, ev: MouseEvent): any; + onDeviceMotion?(this: EventListenerThisType, ev: DeviceMotionEvent): any; + onDeviceMotionCapture?(this: EventListenerThisType, ev: DeviceMotionEvent): any; + onDeviceOrientation?(this: EventListenerThisType, ev: DeviceOrientationEvent): any; + onDeviceOrientationCapture?(this: EventListenerThisType, ev: DeviceOrientationEvent): any; + onDrag?(this: EventListenerThisType, ev: DragEvent): any; + onDragCapture?(this: EventListenerThisType, ev: DragEvent): any; + onDragEnd?(this: EventListenerThisType, ev: DragEvent): any; + onDragEndCapture?(this: EventListenerThisType, ev: DragEvent): any; + onDragEnter?(this: EventListenerThisType, ev: DragEvent): any; + onDragEnterCapture?(this: EventListenerThisType, ev: DragEvent): any; + onDragLeave?(this: EventListenerThisType, ev: DragEvent): any; + onDragLeaveCapture?(this: EventListenerThisType, ev: DragEvent): any; + onDragOver?(this: EventListenerThisType, ev: DragEvent): any; + onDragOverCapture?(this: EventListenerThisType, ev: DragEvent): any; + onDragStart?(this: EventListenerThisType, ev: DragEvent): any; + onDragStartCapture?(this: EventListenerThisType, ev: DragEvent): any; + onDrop?(this: EventListenerThisType, ev: DragEvent): any; + onDropCapture?(this: EventListenerThisType, ev: DragEvent): any; + onDurationChange?(this: EventListenerThisType, ev: Event): any; + onDurationChangeCapture?(this: EventListenerThisType, ev: Event): any; + onEmptied?(this: EventListenerThisType, ev: Event): any; + onEmptiedCapture?(this: EventListenerThisType, ev: Event): any; + onEnded?(this: EventListenerThisType, ev: Event): any; + onEndedCapture?(this: EventListenerThisType, ev: Event): any; + onError?(this: EventListenerThisType, ...args: OnErrorEventHandlerArgs): any; + onErrorCapture?(this: EventListenerThisType, ...args: OnErrorEventHandlerArgs): any; + onFocus?(this: EventListenerThisType, ev: FocusEvent): any; + onFocusCapture?(this: EventListenerThisType, ev: FocusEvent): any; + onHashChange?(this: EventListenerThisType, ev: HashChangeEvent): any; + onHashChangeCapture?(this: EventListenerThisType, ev: HashChangeEvent): any; + onInput?(this: EventListenerThisType, ev: Event): any; + onInputCapture?(this: EventListenerThisType, ev: Event): any; + onKeyDown?(this: EventListenerThisType, ev: KeyboardEvent): any; + onKeyDownCapture?(this: EventListenerThisType, ev: KeyboardEvent): any; + onKeyPress?(this: EventListenerThisType, ev: KeyboardEvent): any; + onKeyPressCapture?(this: EventListenerThisType, ev: KeyboardEvent): any; + onKeyUp?(this: EventListenerThisType, ev: KeyboardEvent): any; + onKeyUpCapture?(this: EventListenerThisType, ev: KeyboardEvent): any; + onLoad?(this: EventListenerThisType, ev: Event): any; + onLoadCapture?(this: EventListenerThisType, ev: Event): any; + onLoadedData?(this: EventListenerThisType, ev: Event): any; + onLoadedDataCapture?(this: EventListenerThisType, ev: Event): any; + onLoadedMetadata?(this: EventListenerThisType, ev: Event): any; + onLoadedMetadataCapture?(this: EventListenerThisType, ev: Event): any; + onLoadStart?(this: EventListenerThisType, ev: Event): any; + onLoadStartCapture?(this: EventListenerThisType, ev: Event): any; + onMessage?(this: EventListenerThisType, ev: MessageEvent): any; + onMessageCapture?(this: EventListenerThisType, ev: MessageEvent): any; + onMouseDown?(this: EventListenerThisType, ev: MouseEvent): any; + onMouseDownCapture?(this: EventListenerThisType, ev: MouseEvent): any; + onMouseEnter?(this: EventListenerThisType, ev: MouseEvent): any; + onMouseEnterCapture?(this: EventListenerThisType, ev: MouseEvent): any; + onMouseLeave?(this: EventListenerThisType, ev: MouseEvent): any; + onMouseLeaveCapture?(this: EventListenerThisType, ev: MouseEvent): any; + onMouseMove?(this: EventListenerThisType, ev: MouseEvent): any; + onMouseMoveCapture?(this: EventListenerThisType, ev: MouseEvent): any; + onMouseOut?(this: EventListenerThisType, ev: MouseEvent): any; + onMouseOutCapture?(this: EventListenerThisType, ev: MouseEvent): any; + onMouseOver?(this: EventListenerThisType, ev: MouseEvent): any; + onMouseOverCapture?(this: EventListenerThisType, ev: MouseEvent): any; + onMouseUp?(this: EventListenerThisType, ev: MouseEvent): any; + onMouseUpCapture?(this: EventListenerThisType, ev: MouseEvent): any; + onMouseWheel?(this: EventListenerThisType, ev: WheelEvent): any; + onMouseWheelCapture?(this: EventListenerThisType, ev: WheelEvent): any; + onMsGestureChange?(this: EventListenerThisType, ev: MSGestureEvent): any; + onMsGestureChangeCapture?(this: EventListenerThisType, ev: MSGestureEvent): any; + onMsGestureDoubleTap?(this: EventListenerThisType, ev: MSGestureEvent): any; + onMsGestureDoubleTapCapture?(this: EventListenerThisType, ev: MSGestureEvent): any; + onMsGestureEnd?(this: EventListenerThisType, ev: MSGestureEvent): any; + onMsGestureEndCapture?(this: EventListenerThisType, ev: MSGestureEvent): any; + onMsGestureHold?(this: EventListenerThisType, ev: MSGestureEvent): any; + onMsGestureHoldCapture?(this: EventListenerThisType, ev: MSGestureEvent): any; + onMsGestureStart?(this: EventListenerThisType, ev: MSGestureEvent): any; + onMsGestureStartCapture?(this: EventListenerThisType, ev: MSGestureEvent): any; + onMsGestureTap?(this: EventListenerThisType, ev: MSGestureEvent): any; + onMsGestureTapCapture?(this: EventListenerThisType, ev: MSGestureEvent): any; + onMsInertiaStart?(this: EventListenerThisType, ev: MSGestureEvent): any; + onMsInertiaStartCapture?(this: EventListenerThisType, ev: MSGestureEvent): any; + onMsPointerCancel?(this: EventListenerThisType, ev: MSPointerEvent): any; + onMsPointerCancelCapture?(this: EventListenerThisType, ev: MSPointerEvent): any; + onMsPointerDown?(this: EventListenerThisType, ev: MSPointerEvent): any; + onMsPointerDownCapture?(this: EventListenerThisType, ev: MSPointerEvent): any; + onMsPointerEnter?(this: EventListenerThisType, ev: MSPointerEvent): any; + onMsPointerEnterCapture?(this: EventListenerThisType, ev: MSPointerEvent): any; + onMsPointerLeave?(this: EventListenerThisType, ev: MSPointerEvent): any; + onMsPointerLeaveCapture?(this: EventListenerThisType, ev: MSPointerEvent): any; + onMsPointerMove?(this: EventListenerThisType, ev: MSPointerEvent): any; + onMsPointerMoveCapture?(this: EventListenerThisType, ev: MSPointerEvent): any; + onMsPointerOut?(this: EventListenerThisType, ev: MSPointerEvent): any; + onMsPointerOutCapture?(this: EventListenerThisType, ev: MSPointerEvent): any; + onMsPointerOver?(this: EventListenerThisType, ev: MSPointerEvent): any; + onMsPointerOverCapture?(this: EventListenerThisType, ev: MSPointerEvent): any; + oNmsPointerUp?(this: EventListenerThisType, ev: MSPointerEvent): any; + oNmsPointerUpCapture?(this: EventListenerThisType, ev: MSPointerEvent): any; + onOffline?(this: EventListenerThisType, ev: Event): any; + onOfflineCapture?(this: EventListenerThisType, ev: Event): any; + onOnline?(this: EventListenerThisType, ev: Event): any; + onOnlineCapture?(this: EventListenerThisType, ev: Event): any; + onOrientationChange?(this: EventListenerThisType, ev: Event): any; + onOrientationChangeCapture?(this: EventListenerThisType, ev: Event): any; + onPageHide?(this: EventListenerThisType, ev: PageTransitionEvent): any; + onPageHideCapture?(this: EventListenerThisType, ev: PageTransitionEvent): any; + onPageShow?(this: EventListenerThisType, ev: PageTransitionEvent): any; + onPageShowCapture?(this: EventListenerThisType, ev: PageTransitionEvent): any; + onPause?(this: EventListenerThisType, ev: Event): any; + onPauseCapture?(this: EventListenerThisType, ev: Event): any; + onPlay?(this: EventListenerThisType, ev: Event): any; + onPlayCapture?(this: EventListenerThisType, ev: Event): any; + onPlaying?(this: EventListenerThisType, ev: Event): any; + onPlayingCapture?(this: EventListenerThisType, ev: Event): any; + onPopState?(this: EventListenerThisType, ev: PopStateEvent): any; + onPopStateCapture?(this: EventListenerThisType, ev: PopStateEvent): any; + onProgress?(this: EventListenerThisType, ev: ProgressEvent): any; + onProgressCapture?(this: EventListenerThisType, ev: ProgressEvent): any; + onRateChange?(this: EventListenerThisType, ev: Event): any; + onRateChangeCapture?(this: EventListenerThisType, ev: Event): any; + onReadyStateChange?(this: EventListenerThisType, ev: ProgressEvent): any; + onReadyStateChangeCapture?(this: EventListenerThisType, ev: ProgressEvent): any; + onReset?(this: EventListenerThisType, ev: Event): any; + onResetCapture?(this: EventListenerThisType, ev: Event): any; + onResize?(this: EventListenerThisType, ev: UIEvent): any; + onResizeCapture?(this: EventListenerThisType, ev: UIEvent): any; + onScroll?(this: EventListenerThisType, ev: UIEvent): any; + onScrollCapture?(this: EventListenerThisType, ev: UIEvent): any; + onSeeked?(this: EventListenerThisType, ev: Event): any; + onSeekedCapture?(this: EventListenerThisType, ev: Event): any; + onSeeking?(this: EventListenerThisType, ev: Event): any; + onSeekingCapture?(this: EventListenerThisType, ev: Event): any; + onSelect?(this: EventListenerThisType, ev: UIEvent): any; + onSelectCapture?(this: EventListenerThisType, ev: UIEvent): any; + onSelectionChange?(this: EventListenerThisType, ev: Event): any; + onSelectionChangeCapture?(this: EventListenerThisType, ev: Event): any; + onStalled?(this: EventListenerThisType, ev: Event): any; + onStalledCapture?(this: EventListenerThisType, ev: Event): any; + onStorage?(this: EventListenerThisType, ev: StorageEvent): any; + onStorageCapture?(this: EventListenerThisType, ev: StorageEvent): any; + onSubmit?(this: EventListenerThisType, ev: Event): any; + onSubmitCapture?(this: EventListenerThisType, ev: Event): any; + onSuspend?(this: EventListenerThisType, ev: Event): any; + onSuspendCapture?(this: EventListenerThisType, ev: Event): any; + onTimeUpdate?(this: EventListenerThisType, ev: Event): any; + onTimeUpdateCapture?(this: EventListenerThisType, ev: Event): any; + onTouchCancel?(this: EventListenerThisType, ev: TouchEvent): any; + onTouchCancelCapture?(this: EventListenerThisType, ev: TouchEvent): any; + onTouchEnd?(this: EventListenerThisType, ev: TouchEvent): any; + onTouchEndCapture?(this: EventListenerThisType, ev: TouchEvent): any; + onTouchMove?(this: EventListenerThisType, ev: TouchEvent): any; + onTouchMoveCapture?(this: EventListenerThisType, ev: TouchEvent): any; + onTouchStart?(this: EventListenerThisType, ev: TouchEvent): any; + onTouchStartCapture?(this: EventListenerThisType, ev: TouchEvent): any; + onUnload?(this: EventListenerThisType, ev: Event): any; + onUnloadCapture?(this: EventListenerThisType, ev: Event): any; + onVolumeChange?(this: EventListenerThisType, ev: Event): any; + onVolumeChangeCapture?(this: EventListenerThisType, ev: Event): any; + onWaiting?(this: EventListenerThisType, ev: Event): any; + onWaitingCapture?(this: EventListenerThisType, ev: Event): any; + + /** + * Target (window or document) + */ + target: T; +} + +export type WindowEventTargets = {[K in keyof Window]: Window[K] extends EventTarget ? K : never}[keyof Window]; + +export default class EventListener extends React.PureComponent> { } diff --git a/types/react-event-listener/ts3.1/react-event-listener-tests.tsx b/types/react-event-listener/ts3.1/react-event-listener-tests.tsx new file mode 100644 index 0000000000..238b05237b --- /dev/null +++ b/types/react-event-listener/ts3.1/react-event-listener-tests.tsx @@ -0,0 +1,9 @@ +import React = require("react"); +import EventListener, { withOptions } from "react-event-listener"; + + { }} />; + { }, { passive: true, capture: true })} />; + { }}/>; + { }} />; +; +; diff --git a/types/react-event-listener/ts3.1/tsconfig.json b/types/react-event-listener/ts3.1/tsconfig.json new file mode 100644 index 0000000000..8b6f2935ea --- /dev/null +++ b/types/react-event-listener/ts3.1/tsconfig.json @@ -0,0 +1,25 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "jsx": "react", + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../../", + "typeRoots": [ + "../../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "react-event-listener-tests.tsx" + ] +} \ No newline at end of file diff --git a/types/react-event-listener/ts3.1/tslint.json b/types/react-event-listener/ts3.1/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/react-event-listener/ts3.1/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }