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

[WIP] Stronger types for React DOM #6727

Closed
wants to merge 12 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions lib/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ type ProgressEventHandler = (event: ProgressEvent) => mixed
type ProgressEventListener = {handleEvent: ProgressEventHandler} | ProgressEventHandler
type DragEventHandler = (event: DragEvent) => mixed
type DragEventListener = {handleEvent: DragEventHandler} | DragEventHandler
type PointerEventHandler = (event: PointerEvent) => mixed
type PointerEventListener = {handleEvent: PointerEventHandler} | PointerEventHandler
type AnimationEventHandler = (event: AnimationEvent) => mixed
type AnimationEventListener = {handleEvent: AnimationEventHandler} | AnimationEventHandler
type ClipboardEventHandler = (event: ClipboardEvent) => mixed
Expand All @@ -146,6 +148,7 @@ type TouchEventTypes = 'touchstart' | 'touchmove' | 'touchend' | 'touchcancel';
type WheelEventTypes = 'wheel';
type ProgressEventTypes = 'abort' | 'error' | 'load' | 'loadend' | 'loadstart' | 'progress' | 'timeout';
type DragEventTypes = 'drag' | 'dragend' | 'dragenter' | 'dragexit' | 'dragleave' | 'dragover' | 'dragstart' | 'drop';
type PointerEventTypes = 'pointerover' | 'pointerenter' | 'pointerdown' | 'pointermove' | 'pointerup' | 'pointercancel' | 'pointerout' | 'pointerleave' | 'gotpointercapture' | 'lostpointercapture';
type AnimationEventTypes = 'animationstart' | 'animationend' | 'animationiteration';
type ClipboardEventTypes = 'clipboardchange' | 'cut' | 'copy' | 'paste';

Expand All @@ -163,6 +166,7 @@ declare class EventTarget {
addEventListener(type: WheelEventTypes, listener: WheelEventListener, optionsOrUseCapture?: EventListenerOptionsOrUseCapture): void;
addEventListener(type: ProgressEventTypes, listener: ProgressEventListener, optionsOrUseCapture?: EventListenerOptionsOrUseCapture): void;
addEventListener(type: DragEventTypes, listener: DragEventListener, optionsOrUseCapture?: EventListenerOptionsOrUseCapture): void;
addEventListener(type: PointerEventTypes, listener: PointerEventListener, optionsOrUseCapture?: EventListenerOptionsOrUseCapture): void;
addEventListener(type: AnimationEventTypes, listener: AnimationEventListener, optionsOrUseCapture?: EventListenerOptionsOrUseCapture): void;
addEventListener(type: ClipboardEventTypes, listener: ClipboardEventListener, optionsOrUseCapture?: EventListenerOptionsOrUseCapture): void;
addEventListener(type: string, listener: EventListener, optionsOrUseCapture?: EventListenerOptionsOrUseCapture): void;
Expand All @@ -174,6 +178,7 @@ declare class EventTarget {
removeEventListener(type: WheelEventTypes, listener: WheelEventListener, optionsOrUseCapture?: EventListenerOptionsOrUseCapture): void;
removeEventListener(type: ProgressEventTypes, listener: ProgressEventListener, optionsOrUseCapture?: EventListenerOptionsOrUseCapture): void;
removeEventListener(type: DragEventTypes, listener: DragEventListener, optionsOrUseCapture?: EventListenerOptionsOrUseCapture): void;
removeEventListener(type: PointerEventTypes, listener: PointerEventListener, optionsOrUseCapture?: EventListenerOptionsOrUseCapture): void;
removeEventListener(type: AnimationEventTypes, listener: AnimationEventListener, optionsOrUseCapture?: EventListenerOptionsOrUseCapture): void;
removeEventListener(type: ClipboardEventTypes, listener: ClipboardEventListener, optionsOrUseCapture?: EventListenerOptionsOrUseCapture): void;
removeEventListener(type: string, listener: EventListener, optionsOrUseCapture?: EventListenerOptionsOrUseCapture): void;
Expand All @@ -185,6 +190,7 @@ declare class EventTarget {
attachEvent?: (type: WheelEventTypes, listener: WheelEventListener) => void;
attachEvent?: (type: ProgressEventTypes, listener: ProgressEventListener) => void;
attachEvent?: (type: DragEventTypes, listener: DragEventListener) => void;
attachEvent?: (type: PointerEventTypes, listener: PointerEventListener) => void;
attachEvent?: (type: AnimationEventTypes, listener: AnimationEventListener) => void;
attachEvent?: (type: ClipboardEventTypes, listener: ClipboardEventListener) => void;
attachEvent?: (type: string, listener: EventListener) => void;
Expand All @@ -196,6 +202,7 @@ declare class EventTarget {
detachEvent?: (type: WheelEventTypes, listener: WheelEventListener) => void;
detachEvent?: (type: ProgressEventTypes, listener: ProgressEventListener) => void;
detachEvent?: (type: DragEventTypes, listener: DragEventListener) => void;
detachEvent?: (type: PointerEventTypes, listener: PointerEventListener) => void;
detachEvent?: (type: AnimationEventTypes, listener: AnimationEventListener) => void;
detachEvent?: (type: ClipboardEventTypes, listener: ClipboardEventListener) => void;
detachEvent?: (type: string, listener: EventListener) => void;
Expand Down Expand Up @@ -322,6 +329,37 @@ declare class DragEvent extends MouseEvent {
dataTransfer: ?DataTransfer; // readonly
}

type PointerEvent$PointerEventInit = MouseEvent$MouseEventInit & {
pointerId?: number;
width?: number;
height?: number;
pressure?: number;
tangentialPressure?: number;
tiltX?: number;
tiltY?: number;
twist?: number;
pointerType?: string;
isPrimary?: boolean;
};

declare class PointerEvent extends MouseEvent {
constructor(
typeArg: string,
pointerEventInit?: PointerEvent$PointerEventInit,
): void;

pointerId: number;
width: number;
height: number;
pressure: number;
tangentialPressure: number;
tiltX: number;
tiltY: number;
twist: number;
pointerType: string;
isPrimary: boolean;
}

declare class ProgressEvent extends Event {
lengthComputable: boolean;
loaded: number;
Expand Down Expand Up @@ -1523,6 +1561,7 @@ declare class HTMLElement extends Element {
onended: ?Function;
onerror: ?Function;
onfocus: ?Function;
ongotpointercapture: ?Function,
oninput: ?Function;
oninvalid: ?Function;
onkeydown: ?Function;
Expand All @@ -1532,6 +1571,7 @@ declare class HTMLElement extends Element {
onloadeddata: ?Function;
onloadedmetadata: ?Function;
onloadstart: ?Function;
onlostpointercapture: ?Function,
onmousedown: ?Function;
onmouseenter: ?Function;
onmouseleave: ?Function;
Expand All @@ -1543,6 +1583,14 @@ declare class HTMLElement extends Element {
onpause: ?Function;
onplay: ?Function;
onplaying: ?Function;
onpointercancel: ?Function,
onpointerdown: ?Function,
onpointerenter: ?Function,
onpointerleave: ?Function,
onpointermove: ?Function,
onpointerout: ?Function,
onpointerover: ?Function,
onpointerup: ?Function,
onprogress: ?Function;
onratechange: ?Function;
onreadystatechange: ?Function;
Expand Down
Loading