From ba40bebaf245a4f6cf51f30855e8a35d40460c20 Mon Sep 17 00:00:00 2001 From: Horiuchi_H Date: Fri, 24 Nov 2017 18:18:17 +0900 Subject: [PATCH 1/3] feat: add new configurations --- types/react-swipeable/index.d.ts | 39 ++++++++++--------- .../react-swipeable/react-swipeable-tests.tsx | 2 + types/react-swipeable/tsconfig.json | 6 +-- 3 files changed, 26 insertions(+), 21 deletions(-) diff --git a/types/react-swipeable/index.d.ts b/types/react-swipeable/index.d.ts index b0036ae119..496f0500cf 100644 --- a/types/react-swipeable/index.d.ts +++ b/types/react-swipeable/index.d.ts @@ -1,7 +1,8 @@ -// Type definitions for react-swipeable 4.0 +// Type definitions for react-swipeable 4.2 // Project: https://www.npmjs.com/package/react-swipeable // Definitions by: Giedrius Grabauskas // Konstantin Vasilev +// Hiroki Horiuchi // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.3 @@ -10,30 +11,32 @@ import * as React from 'react'; declare class ReactSwipeable extends React.Component {} declare namespace ReactSwipeable { - type OnSwipingCallback = (event: React.TouchEvent, deltaX: number, deltaY: number, absX: number, absY: number, velocity: number) => void; - type OnSwipedCallback = (event: React.TouchEvent, deltaX: number, deltaY: number, isFlick: boolean, velocity: number) => void; - type OnSwipedDirectionCallback = (event: React.TouchEvent, delta: number, isFlick: boolean) => void; - type OnSwipingDirectionCallback = (event: React.TouchEvent, delta: number) => void; - type OnTapCallback = (event: React.TouchEvent) => void; + type OnSwipingCallback = (event: React.TouchEvent, deltaX: number, deltaY: number, absX: number, absY: number, velocity: number) => void; + type OnSwipedCallback = (event: React.TouchEvent, deltaX: number, deltaY: number, isFlick: boolean, velocity: number) => void; + type OnSwipedDirectionCallback = (event: React.TouchEvent, delta: number, isFlick: boolean) => void; + type OnSwipingDirectionCallback = (event: React.TouchEvent, delta: number) => void; + type OnTapCallback = (event: React.TouchEvent) => void; - interface SwipeableProps extends React.ClassAttributes, React.HTMLAttributes { - onSwiped?: OnSwipedCallback; - onSwiping?: OnSwipingCallback; - onSwipingUp?: OnSwipingDirectionCallback; - onSwipingRight?: OnSwipingDirectionCallback; - onSwipingDown?: OnSwipingDirectionCallback; - onSwipingLeft?: OnSwipingDirectionCallback; - onSwipedUp?: OnSwipedDirectionCallback; - onSwipedRight?: OnSwipedDirectionCallback; - onSwipedDown?: OnSwipedDirectionCallback; - onSwipedLeft?: OnSwipedDirectionCallback; - onTap?: OnTapCallback; + interface SwipeableProps extends React.ClassAttributes, React.HTMLAttributes { + onSwiped?: OnSwipedCallback; + onSwiping?: OnSwipingCallback; + onSwipingUp?: OnSwipingDirectionCallback; + onSwipingRight?: OnSwipingDirectionCallback; + onSwipingDown?: OnSwipingDirectionCallback; + onSwipingLeft?: OnSwipingDirectionCallback; + onSwipedUp?: OnSwipedDirectionCallback; + onSwipedRight?: OnSwipedDirectionCallback; + onSwipedDown?: OnSwipedDirectionCallback; + onSwipedLeft?: OnSwipedDirectionCallback; + onTap?: OnTapCallback; flickThreshold?: number; delta?: number; preventDefaultTouchmoveEvent?: boolean; stopPropagation?: boolean; nodeName?: string; trackMouse?: boolean; + disabled?: boolean; + innerRef?: React.Ref; children?: React.ReactNode; } } diff --git a/types/react-swipeable/react-swipeable-tests.tsx b/types/react-swipeable/react-swipeable-tests.tsx index 61093a203e..4fa67abffa 100644 --- a/types/react-swipeable/react-swipeable-tests.tsx +++ b/types/react-swipeable/react-swipeable-tests.tsx @@ -35,6 +35,8 @@ class SampleComponent extends React.PureComponent { stopPropagation nodeName="swipe" trackMouse + disabled + innerRef="swipe-ref" onClick={this.handleClick} >
diff --git a/types/react-swipeable/tsconfig.json b/types/react-swipeable/tsconfig.json index 0d676ade9b..a720949edf 100644 --- a/types/react-swipeable/tsconfig.json +++ b/types/react-swipeable/tsconfig.json @@ -6,8 +6,8 @@ "dom" ], "noImplicitAny": true, - "noImplicitThis": false, - "strictNullChecks": false, + "noImplicitThis": true, + "strictNullChecks": true, "strictFunctionTypes": true, "baseUrl": "../", "typeRoots": [ @@ -22,4 +22,4 @@ "index.d.ts", "react-swipeable-tests.tsx" ] -} \ No newline at end of file +} From c8a445c4f1fa33cceee217e4439a54107338a154 Mon Sep 17 00:00:00 2001 From: Horiuchi_H Date: Mon, 27 Nov 2017 13:22:27 +0900 Subject: [PATCH 2/3] feat: add generic type test --- types/react-swipeable/index.d.ts | 4 ++-- types/react-swipeable/react-swipeable-tests.tsx | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/types/react-swipeable/index.d.ts b/types/react-swipeable/index.d.ts index 496f0500cf..1608258c64 100644 --- a/types/react-swipeable/index.d.ts +++ b/types/react-swipeable/index.d.ts @@ -8,7 +8,7 @@ import * as React from 'react'; -declare class ReactSwipeable extends React.Component {} +declare class ReactSwipeable extends React.Component> {} declare namespace ReactSwipeable { type OnSwipingCallback = (event: React.TouchEvent, deltaX: number, deltaY: number, absX: number, absY: number, velocity: number) => void; @@ -17,7 +17,7 @@ declare namespace ReactSwipeable { type OnSwipingDirectionCallback = (event: React.TouchEvent, delta: number) => void; type OnTapCallback = (event: React.TouchEvent) => void; - interface SwipeableProps extends React.ClassAttributes, React.HTMLAttributes { + interface SwipeableProps extends React.ClassAttributes>, React.HTMLAttributes { onSwiped?: OnSwipedCallback; onSwiping?: OnSwipingCallback; onSwipingUp?: OnSwipingDirectionCallback; diff --git a/types/react-swipeable/react-swipeable-tests.tsx b/types/react-swipeable/react-swipeable-tests.tsx index 4fa67abffa..d39f1a1b11 100644 --- a/types/react-swipeable/react-swipeable-tests.tsx +++ b/types/react-swipeable/react-swipeable-tests.tsx @@ -46,3 +46,16 @@ class SampleComponent extends React.PureComponent { ); } } + +class DivSwipeable extends Swipeable {} +const TestComponent: React.StatelessComponent<{}> = (_) => { + const handleSwiped = (event: React.TouchEvent) => {}; + return ( + +
this is sample code.
+
+ ); +}; From c78315abf325ce1f5e10b3ec18a9bb09c3d156d0 Mon Sep 17 00:00:00 2001 From: Horiuchi_H Date: Mon, 27 Nov 2017 13:34:14 +0900 Subject: [PATCH 3/3] fix: tslint error --- types/react-swipeable/react-swipeable-tests.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/react-swipeable/react-swipeable-tests.tsx b/types/react-swipeable/react-swipeable-tests.tsx index d39f1a1b11..ed5df52e54 100644 --- a/types/react-swipeable/react-swipeable-tests.tsx +++ b/types/react-swipeable/react-swipeable-tests.tsx @@ -48,7 +48,7 @@ class SampleComponent extends React.PureComponent { } class DivSwipeable extends Swipeable {} -const TestComponent: React.StatelessComponent<{}> = (_) => { +const TestComponent: React.StatelessComponent = (_) => { const handleSwiped = (event: React.TouchEvent) => {}; return (