From b480e92ae719f458f34e10d0f719c6c5f7159cf4 Mon Sep 17 00:00:00 2001 From: jrasmusbm Date: Tue, 14 Aug 2018 10:24:47 +0200 Subject: [PATCH 001/320] Add react-visibility-sensor --- types/react-visibility-sensor/index.d.ts | 36 ++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 types/react-visibility-sensor/index.d.ts diff --git a/types/react-visibility-sensor/index.d.ts b/types/react-visibility-sensor/index.d.ts new file mode 100644 index 0000000000..0ba06eccee --- /dev/null +++ b/types/react-visibility-sensor/index.d.ts @@ -0,0 +1,36 @@ +// Type definitions for react-visibility-sensor 3.11.1 +// Project: https://github.com/joshwnj/react-visibility-sensor +// Definitions by: Rasmus Bergström +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +declare module "react-visibility-sensor" { + import * as React from "react"; + + interface Shape { + top?: number; + left?: number; + bottom?: number; + right?: number; + } + + interface Props { + onChange: (isVisible: boolean, visibilityRect?: Shape) => void; + active?: boolean; + partialVisibility?: boolean; + offset?: Shape; + minTopValue?: number; + intervalCheck?: boolean; + intervalDelay?: number; + scrollCheck?: boolean; + scrollDelay?: number; + scrollThrottle?: number; + resizeCheck?: boolean; + resizeDelay?: number; + resizeThrottle?: number; + delayedCall?: boolean; + } + + const ReactVisibilitySensor: React.StatelessComponent; + + export = ReactVisibilitySensor; +} From 66e4c9349c38885cbcef17a4420b9e5be6b7f582 Mon Sep 17 00:00:00 2001 From: jrasmusbm Date: Tue, 14 Aug 2018 10:36:06 +0200 Subject: [PATCH 002/320] Add ts-config for react-visibility-sensor --- types/react-visibility-sensor/tsconfig.json | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 types/react-visibility-sensor/tsconfig.json diff --git a/types/react-visibility-sensor/tsconfig.json b/types/react-visibility-sensor/tsconfig.json new file mode 100644 index 0000000000..057c8e9b0b --- /dev/null +++ b/types/react-visibility-sensor/tsconfig.json @@ -0,0 +1,17 @@ +{ + "compilerOptions": { + "module": "esnext", + "lib": ["es7", "dom"], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "jsx": "react", + "typeRoots": ["../"], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": ["index.d.ts", "tests.tsx"] +} From c6cdeef61a4cc4f09df2c8b6090d30bbdf244299 Mon Sep 17 00:00:00 2001 From: jrasmusbm Date: Tue, 14 Aug 2018 10:39:19 +0200 Subject: [PATCH 003/320] Rename tests file conform documentation --- types/react-visibility-sensor/react-visibility-sensor-tests.tsx | 1 + types/react-visibility-sensor/tsconfig.json | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 types/react-visibility-sensor/react-visibility-sensor-tests.tsx diff --git a/types/react-visibility-sensor/react-visibility-sensor-tests.tsx b/types/react-visibility-sensor/react-visibility-sensor-tests.tsx new file mode 100644 index 0000000000..7b85954889 --- /dev/null +++ b/types/react-visibility-sensor/react-visibility-sensor-tests.tsx @@ -0,0 +1 @@ +export default null diff --git a/types/react-visibility-sensor/tsconfig.json b/types/react-visibility-sensor/tsconfig.json index 057c8e9b0b..304331bed3 100644 --- a/types/react-visibility-sensor/tsconfig.json +++ b/types/react-visibility-sensor/tsconfig.json @@ -13,5 +13,5 @@ "noEmit": true, "forceConsistentCasingInFileNames": true }, - "files": ["index.d.ts", "tests.tsx"] + "files": ["index.d.ts", "react-visibility-sensor-tests.tsx"] } From cb8f091f6cb6d25a81fb202636754bca87f7288b Mon Sep 17 00:00:00 2001 From: jrasmusbm Date: Tue, 14 Aug 2018 10:44:25 +0200 Subject: [PATCH 004/320] Add Typescript version --- types/react-visibility-sensor/index.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/types/react-visibility-sensor/index.d.ts b/types/react-visibility-sensor/index.d.ts index 0ba06eccee..8f32bde0d4 100644 --- a/types/react-visibility-sensor/index.d.ts +++ b/types/react-visibility-sensor/index.d.ts @@ -2,6 +2,7 @@ // Project: https://github.com/joshwnj/react-visibility-sensor // Definitions by: Rasmus Bergström // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// Typescript 3.0.1 declare module "react-visibility-sensor" { import * as React from "react"; From d6db1cbc831f56ac2667eb86eb0057756d36bbab Mon Sep 17 00:00:00 2001 From: jrasmusbm Date: Tue, 14 Aug 2018 10:46:56 +0200 Subject: [PATCH 005/320] Fix typo --- types/react-visibility-sensor/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/react-visibility-sensor/index.d.ts b/types/react-visibility-sensor/index.d.ts index 8f32bde0d4..5bfae449ea 100644 --- a/types/react-visibility-sensor/index.d.ts +++ b/types/react-visibility-sensor/index.d.ts @@ -2,7 +2,7 @@ // Project: https://github.com/joshwnj/react-visibility-sensor // Definitions by: Rasmus Bergström // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// Typescript 3.0.1 +// Typescript Version: 3.0 declare module "react-visibility-sensor" { import * as React from "react"; From 37b615e01196c62ce5652ced6e9cacb8b7b2031a Mon Sep 17 00:00:00 2001 From: jrasmusbm Date: Tue, 14 Aug 2018 11:14:23 +0200 Subject: [PATCH 006/320] Fix another typo --- types/react-visibility-sensor/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/react-visibility-sensor/index.d.ts b/types/react-visibility-sensor/index.d.ts index 5bfae449ea..6d20ade01a 100644 --- a/types/react-visibility-sensor/index.d.ts +++ b/types/react-visibility-sensor/index.d.ts @@ -2,7 +2,7 @@ // Project: https://github.com/joshwnj/react-visibility-sensor // Definitions by: Rasmus Bergström // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// Typescript Version: 3.0 +// TypeScript Version: 3.0 declare module "react-visibility-sensor" { import * as React from "react"; From f023c3b7421e38a476c2579605923baad2145fed Mon Sep 17 00:00:00 2001 From: jrasmusbm Date: Tue, 14 Aug 2018 11:29:43 +0200 Subject: [PATCH 007/320] Change TypeScript version --- types/react-visibility-sensor/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/react-visibility-sensor/index.d.ts b/types/react-visibility-sensor/index.d.ts index 6d20ade01a..9259d7876a 100644 --- a/types/react-visibility-sensor/index.d.ts +++ b/types/react-visibility-sensor/index.d.ts @@ -2,7 +2,7 @@ // Project: https://github.com/joshwnj/react-visibility-sensor // Definitions by: Rasmus Bergström // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 3.0 +// TypeScript Version: 2.7 declare module "react-visibility-sensor" { import * as React from "react"; From 281aeb56b946d0a1ea275222068f92059e22188b Mon Sep 17 00:00:00 2001 From: jrasmusbm Date: Wed, 29 Aug 2018 10:14:53 +0200 Subject: [PATCH 008/320] Add type reference link --- types/react-visibility-sensor/index.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/types/react-visibility-sensor/index.d.ts b/types/react-visibility-sensor/index.d.ts index 9259d7876a..50e134b73a 100644 --- a/types/react-visibility-sensor/index.d.ts +++ b/types/react-visibility-sensor/index.d.ts @@ -5,6 +5,7 @@ // TypeScript Version: 2.7 declare module "react-visibility-sensor" { + /// import * as React from "react"; interface Shape { From 72a7247089c167355dc5d155404a8524c38a5501 Mon Sep 17 00:00:00 2001 From: jrasmusbm Date: Wed, 29 Aug 2018 10:56:18 +0200 Subject: [PATCH 009/320] Fix TypeScript Version --- types/react-visibility-sensor/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/react-visibility-sensor/index.d.ts b/types/react-visibility-sensor/index.d.ts index 50e134b73a..a490952cb4 100644 --- a/types/react-visibility-sensor/index.d.ts +++ b/types/react-visibility-sensor/index.d.ts @@ -2,7 +2,7 @@ // Project: https://github.com/joshwnj/react-visibility-sensor // Definitions by: Rasmus Bergström // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.7 +// TypeScript Version: 2.8 declare module "react-visibility-sensor" { /// From 4dff6b7da4bfef257ad06b8e6af42b7d62d4944f Mon Sep 17 00:00:00 2001 From: jrasmusbm Date: Wed, 29 Aug 2018 11:00:56 +0200 Subject: [PATCH 010/320] Add tslint.json --- types/react-visibility-sensor/tslint.json | 1 + 1 file changed, 1 insertion(+) create mode 100644 types/react-visibility-sensor/tslint.json diff --git a/types/react-visibility-sensor/tslint.json b/types/react-visibility-sensor/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/react-visibility-sensor/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } From b553b09b386275713ae0e2819b06ccd6ebe8b344 Mon Sep 17 00:00:00 2001 From: jrasmusbm Date: Wed, 29 Aug 2018 11:46:48 +0200 Subject: [PATCH 011/320] Add tests and make them pass --- types/react-visibility-sensor/index.d.ts | 59 +++++++++---------- .../react-visibility-sensor-tests.tsx | 26 +++++++- types/react-visibility-sensor/tsconfig.json | 2 +- 3 files changed, 54 insertions(+), 33 deletions(-) diff --git a/types/react-visibility-sensor/index.d.ts b/types/react-visibility-sensor/index.d.ts index a490952cb4..2d435c61f7 100644 --- a/types/react-visibility-sensor/index.d.ts +++ b/types/react-visibility-sensor/index.d.ts @@ -1,38 +1,35 @@ -// Type definitions for react-visibility-sensor 3.11.1 +// Type definitions for react-visibility-sensor 3.11 // Project: https://github.com/joshwnj/react-visibility-sensor // Definitions by: Rasmus Bergström // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.8 -declare module "react-visibility-sensor" { - /// - import * as React from "react"; +import * as React from "react"; - interface Shape { - top?: number; - left?: number; - bottom?: number; - right?: number; - } - - interface Props { - onChange: (isVisible: boolean, visibilityRect?: Shape) => void; - active?: boolean; - partialVisibility?: boolean; - offset?: Shape; - minTopValue?: number; - intervalCheck?: boolean; - intervalDelay?: number; - scrollCheck?: boolean; - scrollDelay?: number; - scrollThrottle?: number; - resizeCheck?: boolean; - resizeDelay?: number; - resizeThrottle?: number; - delayedCall?: boolean; - } - - const ReactVisibilitySensor: React.StatelessComponent; - - export = ReactVisibilitySensor; +interface Shape { + top?: number; + left?: number; + bottom?: number; + right?: number; } + +interface Props { + onChange: (isVisible: boolean, visibilityRect?: Shape) => void; + active?: boolean; + partialVisibility?: boolean; + offset?: Shape; + minTopValue?: number; + intervalCheck?: boolean; + intervalDelay?: number; + scrollCheck?: boolean; + scrollDelay?: number; + scrollThrottle?: number; + resizeCheck?: boolean; + resizeDelay?: number; + resizeThrottle?: number; + delayedCall?: boolean; +} + +declare const ReactVisibilitySensor: React.StatelessComponent; + +export default ReactVisibilitySensor; diff --git a/types/react-visibility-sensor/react-visibility-sensor-tests.tsx b/types/react-visibility-sensor/react-visibility-sensor-tests.tsx index 7b85954889..36a4687fe7 100644 --- a/types/react-visibility-sensor/react-visibility-sensor-tests.tsx +++ b/types/react-visibility-sensor/react-visibility-sensor-tests.tsx @@ -1 +1,25 @@ -export default null +import * as React from "react"; + +import ReactVisibilitySensor from "react-visibility-sensor"; +const num = 1; +const bool = true; +const shape = { top: num, left: num, bottom: num, right: num }; + +const component = ( + {}} + active={bool} + partialVisibility={bool} + offset={shape} + minTopValue={num} + intervalCheck={bool} + intervalDelay={num} + scrollCheck={bool} + scrollDelay={num} + scrollThrottle={num} + resizeCheck={bool} + resizeDelay={num} + resizeThrottle={num} + delayedCall={bool} + /> +); diff --git a/types/react-visibility-sensor/tsconfig.json b/types/react-visibility-sensor/tsconfig.json index 304331bed3..ad9bbbdf5c 100644 --- a/types/react-visibility-sensor/tsconfig.json +++ b/types/react-visibility-sensor/tsconfig.json @@ -1,6 +1,6 @@ { "compilerOptions": { - "module": "esnext", + "module": "commonjs", "lib": ["es7", "dom"], "noImplicitAny": true, "noImplicitThis": true, From 38733696c8a8ea88d9fd37b28f0bce0ed5f3ea78 Mon Sep 17 00:00:00 2001 From: jrasmusbm Date: Wed, 29 Aug 2018 12:06:06 +0200 Subject: [PATCH 012/320] Add children --- types/react-visibility-sensor/index.d.ts | 3 +++ .../react-visibility-sensor-tests.tsx | 5 +++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/types/react-visibility-sensor/index.d.ts b/types/react-visibility-sensor/index.d.ts index 2d435c61f7..15ca04d262 100644 --- a/types/react-visibility-sensor/index.d.ts +++ b/types/react-visibility-sensor/index.d.ts @@ -28,6 +28,9 @@ interface Props { resizeDelay?: number; resizeThrottle?: number; delayedCall?: boolean; + children?: ( + args: { isVisible: boolean; visibilityRect?: Shape } + ) => React.ReactNode; } declare const ReactVisibilitySensor: React.StatelessComponent; diff --git a/types/react-visibility-sensor/react-visibility-sensor-tests.tsx b/types/react-visibility-sensor/react-visibility-sensor-tests.tsx index 36a4687fe7..e71cd0e20e 100644 --- a/types/react-visibility-sensor/react-visibility-sensor-tests.tsx +++ b/types/react-visibility-sensor/react-visibility-sensor-tests.tsx @@ -20,6 +20,7 @@ const component = ( resizeCheck={bool} resizeDelay={num} resizeThrottle={num} - delayedCall={bool} - /> + delayedCall={bool}> + {({ isVisible: bool, visibilityRect: shape }) =>
} + ); From 7a544a8216ef512631271307d5435cd6cf18a7b5 Mon Sep 17 00:00:00 2001 From: jrasmusbm Date: Wed, 29 Aug 2018 13:24:25 +0200 Subject: [PATCH 013/320] Use dts-gen template --- types/react-visibility-sensor/index.d.ts | 2 +- types/react-visibility-sensor/tsconfig.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/types/react-visibility-sensor/index.d.ts b/types/react-visibility-sensor/index.d.ts index 15ca04d262..5898f1b8ad 100644 --- a/types/react-visibility-sensor/index.d.ts +++ b/types/react-visibility-sensor/index.d.ts @@ -1,5 +1,5 @@ // Type definitions for react-visibility-sensor 3.11 -// Project: https://github.com/joshwnj/react-visibility-sensor +// Project: https://github.com/joshwnj/react-visibility-sensor#readme // Definitions by: Rasmus Bergström // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.8 diff --git a/types/react-visibility-sensor/tsconfig.json b/types/react-visibility-sensor/tsconfig.json index ad9bbbdf5c..29d5985cfe 100644 --- a/types/react-visibility-sensor/tsconfig.json +++ b/types/react-visibility-sensor/tsconfig.json @@ -6,8 +6,8 @@ "noImplicitThis": true, "strictNullChecks": true, "strictFunctionTypes": true, - "baseUrl": "../", "jsx": "react", + "baseUrl": "../", "typeRoots": ["../"], "types": [], "noEmit": true, From dda5b233ced87c596001b0174c68261cdaf69443 Mon Sep 17 00:00:00 2001 From: jrasmusbm Date: Thu, 30 Aug 2018 09:11:51 +0200 Subject: [PATCH 014/320] Export Shape conform code review https://github.com/DefinitelyTyped/DefinitelyTyped/pull/28493#commitcomment-30333784 --- types/react-visibility-sensor/index.d.ts | 2 +- .../react-visibility-sensor/react-visibility-sensor-tests.tsx | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/types/react-visibility-sensor/index.d.ts b/types/react-visibility-sensor/index.d.ts index 5898f1b8ad..2aa3b9adde 100644 --- a/types/react-visibility-sensor/index.d.ts +++ b/types/react-visibility-sensor/index.d.ts @@ -6,7 +6,7 @@ import * as React from "react"; -interface Shape { +export interface Shape { top?: number; left?: number; bottom?: number; diff --git a/types/react-visibility-sensor/react-visibility-sensor-tests.tsx b/types/react-visibility-sensor/react-visibility-sensor-tests.tsx index e71cd0e20e..9c8e552479 100644 --- a/types/react-visibility-sensor/react-visibility-sensor-tests.tsx +++ b/types/react-visibility-sensor/react-visibility-sensor-tests.tsx @@ -1,9 +1,9 @@ import * as React from "react"; -import ReactVisibilitySensor from "react-visibility-sensor"; +import ReactVisibilitySensor, { Shape } from "react-visibility-sensor"; const num = 1; const bool = true; -const shape = { top: num, left: num, bottom: num, right: num }; +const shape: Shape = { top: num, left: num, bottom: num, right: num }; const component = ( Date: Wed, 5 Sep 2018 10:46:22 +0200 Subject: [PATCH 015/320] Perform changes conform instructions from armanio123 --- types/react-visibility-sensor/index.d.ts | 6 ++++-- .../react-visibility-sensor-tests.tsx | 5 +++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/types/react-visibility-sensor/index.d.ts b/types/react-visibility-sensor/index.d.ts index 2aa3b9adde..9e8776cb8f 100644 --- a/types/react-visibility-sensor/index.d.ts +++ b/types/react-visibility-sensor/index.d.ts @@ -6,7 +6,9 @@ import * as React from "react"; -export interface Shape { +export as namespace ReactVisibilitySensor; + +interface Shape { top?: number; left?: number; bottom?: number; @@ -35,4 +37,4 @@ interface Props { declare const ReactVisibilitySensor: React.StatelessComponent; -export default ReactVisibilitySensor; +export = ReactVisibilitySensor; diff --git a/types/react-visibility-sensor/react-visibility-sensor-tests.tsx b/types/react-visibility-sensor/react-visibility-sensor-tests.tsx index 9c8e552479..9dca0efb34 100644 --- a/types/react-visibility-sensor/react-visibility-sensor-tests.tsx +++ b/types/react-visibility-sensor/react-visibility-sensor-tests.tsx @@ -1,9 +1,10 @@ import * as React from "react"; -import ReactVisibilitySensor, { Shape } from "react-visibility-sensor"; +import * as ReactVisibilitySensor from "react-visibility-sensor"; + const num = 1; const bool = true; -const shape: Shape = { top: num, left: num, bottom: num, right: num }; +const shape = { top: num, left: num, bottom: num, right: num }; const component = ( Date: Fri, 7 Sep 2018 14:49:19 +0900 Subject: [PATCH 016/320] [three] 'webvr-api' is no longer needed. --- types/three/three-vrcontrols.d.ts | 2 -- types/three/three-vreffect.d.ts | 4 +--- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/types/three/three-vrcontrols.d.ts b/types/three/three-vrcontrols.d.ts index a70839994d..22d9974338 100644 --- a/types/three/three-vrcontrols.d.ts +++ b/types/three/three-vrcontrols.d.ts @@ -1,5 +1,3 @@ -/// - import { Camera } from "./three-core"; export class VRControls { diff --git a/types/three/three-vreffect.d.ts b/types/three/three-vreffect.d.ts index e34a24a3ae..b0f22ed91c 100644 --- a/types/three/three-vreffect.d.ts +++ b/types/three/three-vreffect.d.ts @@ -1,5 +1,3 @@ -/// - import { Camera, Matrix4, Renderer, Scene } from "./three-core"; export class VREffect { @@ -32,4 +30,4 @@ export interface VRFov { export interface VREffectOffset { scale: number; offset: number; -} \ No newline at end of file +} From abc7337d28c16fa24e20068fda6d6d95199ed1ee Mon Sep 17 00:00:00 2001 From: Satoshi Nakagawa Date: Fri, 7 Sep 2018 15:15:02 +0900 Subject: [PATCH 017/320] add '// TypeScript Version: 2.8' --- types/three/index.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/types/three/index.d.ts b/types/three/index.d.ts index 5b4a156e4b..61992b95c3 100644 --- a/types/three/index.d.ts +++ b/types/three/index.d.ts @@ -21,6 +21,7 @@ // Ethan Kay , // Methuselah96 // Definitions: https://github.com//DefinitelyTyped +// TypeScript Version: 2.8 export * from "./three-core"; From 3758199f398442a4130ff9c4f4a3c61219485f23 Mon Sep 17 00:00:00 2001 From: Satoshi Nakagawa Date: Fri, 7 Sep 2018 15:29:24 +0900 Subject: [PATCH 018/320] Require TypeScript Version 2.8 in three --- types/aframe/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/aframe/index.d.ts b/types/aframe/index.d.ts index b405de0273..5d0d7d336a 100644 --- a/types/aframe/index.d.ts +++ b/types/aframe/index.d.ts @@ -4,7 +4,7 @@ // Roberto Ritger // Trygve Wastvedt // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.3 +// TypeScript Version: 2.8 /** * Extended tests available at https://github.com/devpaul/aframe-typings.git From c95940783a6d70d82f24c60f926c6d95249d30dd Mon Sep 17 00:00:00 2001 From: Satoshi Nakagawa Date: Fri, 7 Sep 2018 15:37:17 +0900 Subject: [PATCH 019/320] Require TypeScript Version 2.8 in three --- types/physijs/index.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/types/physijs/index.d.ts b/types/physijs/index.d.ts index 79698c4697..6c28bb1048 100644 --- a/types/physijs/index.d.ts +++ b/types/physijs/index.d.ts @@ -2,6 +2,7 @@ // Project: http://chandlerprall.github.io/Physijs/ // Definitions by: Satoru Kimura // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.8 /// From 2546493425cb1c47ed092f2343ffc8a2bd675b81 Mon Sep 17 00:00:00 2001 From: Sebastian Silbermann Date: Wed, 22 Aug 2018 19:10:48 +0200 Subject: [PATCH 020/320] react-jss: add definitions --- types/react-jss/index.d.ts | 26 ++++++ types/react-jss/lib/JssProvider.d.ts | 14 ++++ types/react-jss/lib/injectSheet.d.ts | 116 +++++++++++++++++++++++++++ types/react-jss/package.json | 8 ++ types/react-jss/react-jss-tests.tsx | 97 ++++++++++++++++++++++ types/react-jss/tsconfig.json | 26 ++++++ types/react-jss/tslint.json | 1 + 7 files changed, 288 insertions(+) create mode 100644 types/react-jss/index.d.ts create mode 100644 types/react-jss/lib/JssProvider.d.ts create mode 100644 types/react-jss/lib/injectSheet.d.ts create mode 100644 types/react-jss/package.json create mode 100644 types/react-jss/react-jss-tests.tsx create mode 100644 types/react-jss/tsconfig.json create mode 100644 types/react-jss/tslint.json diff --git a/types/react-jss/index.d.ts b/types/react-jss/index.d.ts new file mode 100644 index 0000000000..7656897a08 --- /dev/null +++ b/types/react-jss/index.d.ts @@ -0,0 +1,26 @@ +// Type definitions for react-jss 8.6 +// Project: https://github.com/cssinjs/react-jss#readme +// Definitions by: Sebastian Silbermann +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.8 +import { createGenerateClassName, JSS, SheetsRegistry } from "jss"; +import * as React from "react"; +import { createTheming, ThemeProvider, withTheme } from "theming"; + +import injectSheet from "./lib/injectSheet"; +import JssProvider, { Props as JssProviderProps } from "./lib/JssProvider"; + +// re-export types +export * from "./lib/injectSheet"; +export { JssProviderProps }; +// library implementations +export const jss: JSS; +export { + createGenerateClassName, + createTheming, + JssProvider, + SheetsRegistry, + ThemeProvider, + withTheme +}; +export default injectSheet; diff --git a/types/react-jss/lib/JssProvider.d.ts b/types/react-jss/lib/JssProvider.d.ts new file mode 100644 index 0000000000..bde15a8ce9 --- /dev/null +++ b/types/react-jss/lib/JssProvider.d.ts @@ -0,0 +1,14 @@ +import * as React from "react"; + +import { GenerateClassName, JSS, SheetsRegistry } from "jss"; + +export interface Props { + children: React.ReactNode; + classNamePrefix?: string; + disableStylesGeneration?: boolean; + jss?: JSS; + generateClassName?: GenerateClassName; + registry?: SheetsRegistry; +} + +export default class JssProvider extends React.Component {} diff --git a/types/react-jss/lib/injectSheet.d.ts b/types/react-jss/lib/injectSheet.d.ts new file mode 100644 index 0000000000..fd66af5c38 --- /dev/null +++ b/types/react-jss/lib/injectSheet.d.ts @@ -0,0 +1,116 @@ +import * as CSS from "csstype"; +import { CreateStyleSheetOptions, JSS } from "jss"; +import * as React from "react"; +import { + channel, + createTheming, + themeListener, + ThemeProvider, + withTheme +} from "theming"; + +/** + * omit from T every key K + * + * @internal + */ +export type Omit = Pick>; +/** + * `T extends ConsistentWith` means that where `T` has overlapping properties with + * `U`, their value types do not conflict. + * + * @internal + */ +export type ConsistentWith = { + [P in keyof DecorationTargetProps]: P extends keyof InjectedProps + ? InjectedProps[P] extends DecorationTargetProps[P] + ? DecorationTargetProps[P] + : InjectedProps[P] + : DecorationTargetProps[P] +}; + +/** + * Like `T & U`, but using the value types from `U` where their properties overlap. + * + * @internal + */ +export type Overwrite = Omit & U; + +/** + * @internal + */ +export type PropsOf = C extends new (props: infer P) => React.Component + ? P + : C extends (props: infer P) => React.ReactElement | null ? P : never; + +/** + * a function that takes {component} and returns a component that passes along + * all the props to {component} except the {InjectedProps} and will accept + * additional {AdditionalProps} + * + * source mui-org/material-ui#12673 + * @internal + */ +export type PropInjector = < + C extends React.ComponentType, InjectedProps>> +>( + component: C +) => React.ComponentType< + Omit>, keyof InjectedProps> & + AdditionalProps +>; + +export interface CSSProperties extends CSS.Properties { + // Allow pseudo selectors and media queries + [k: string]: + | CSS.Properties[keyof CSS.Properties] + | CSSProperties; +} +export type Styles = Record< + ClassKey, + CSSProperties +>; +export type StyleCreator = ( + theme: T +) => Styles; + +export interface Theming { + channel: string; + createTheming: typeof createTheming; + themeListener: typeof themeListener; + ThemeProvider: typeof ThemeProvider; + withTheme: typeof withTheme; +} +export interface InjectOptions extends CreateStyleSheetOptions { + jss?: JSS; + theming?: Theming; +} + +export type ClassNameMap = Record; +export type WithSheet< + S extends string | Styles | StyleCreator, + GivenTheme = undefined +> = { + classes: ClassNameMap< + S extends string + ? S + : S extends StyleCreator + ? C + : S extends Styles ? C : never + >; +} & WithTheme ? T : GivenTheme>; + +export interface WithTheme { + theme: T; + innerRef?: React.Ref | React.RefObject; +} + +export interface StyledComponentProps { + classes?: Partial>; + innerRef?: React.Ref | React.RefObject; +} + +export default function injectSheet( + stylesOrCreator: Styles | StyleCreator, + options?: InjectOptions +): PropInjector, StyledComponentProps>; diff --git a/types/react-jss/package.json b/types/react-jss/package.json new file mode 100644 index 0000000000..2010e4d437 --- /dev/null +++ b/types/react-jss/package.json @@ -0,0 +1,8 @@ +{ + "private": true, + "dependencies": { + "csstype": "^2.0.0", + "jss": "^9.5.0", + "theming": "^1.3.0" + } +} diff --git a/types/react-jss/react-jss-tests.tsx b/types/react-jss/react-jss-tests.tsx new file mode 100644 index 0000000000..803170bb99 --- /dev/null +++ b/types/react-jss/react-jss-tests.tsx @@ -0,0 +1,97 @@ +import * as React from "react"; +import injectSheet, { + JssProvider, + SheetsRegistry, + Styles, + WithSheet, + ThemeProvider +} from "react-jss"; + +interface MyTheme { + color: { + primary: string; + secondary: string; + }; +} + +/** + * helper function to counter typescripts type widening + */ +function createStyles(styles: Styles): Styles { + return styles; +} + +const styles = (theme: MyTheme) => + createStyles({ + myButton: { + color: theme.color.primary, + margin: 1, + "& span": { + fontWeight: "revert" + } + }, + myLabel: { + fontStyle: "italic" + } + }); + +interface ButtonProps extends WithSheet { + label: string; +} + +const Button: React.SFC = ({ classes, children }) => { + return ( + + ); +}; + +const ManuallyStyles = () => { + return ( +