From d8ca2bf318bedb93f017b0524db1bb802ef2f8f4 Mon Sep 17 00:00:00 2001 From: Jake Richards Date: Mon, 8 Oct 2018 12:17:54 -0400 Subject: [PATCH] Adding types for react-window-size (#29507) --- types/react-window-size/index.d.ts | 16 +++++++++++++ .../react-window-size-tests.tsx | 23 ++++++++++++++++++ types/react-window-size/tsconfig.json | 24 +++++++++++++++++++ types/react-window-size/tslint.json | 1 + 4 files changed, 64 insertions(+) create mode 100644 types/react-window-size/index.d.ts create mode 100644 types/react-window-size/react-window-size-tests.tsx create mode 100644 types/react-window-size/tsconfig.json create mode 100644 types/react-window-size/tslint.json diff --git a/types/react-window-size/index.d.ts b/types/react-window-size/index.d.ts new file mode 100644 index 0000000000..8fe1a8fb8d --- /dev/null +++ b/types/react-window-size/index.d.ts @@ -0,0 +1,16 @@ +// Type definitions for react-window-size 1.2 +// Project: https://github.com/finnfiddle/react-window-size +// Definitions by: Jake Richards +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.8 + +import { ComponentType } from 'react'; + +export interface WindowSizeProps { + windowHeight: number; + windowWidth: number; +} + +export default function( + ComposedComponent: ComponentType, +): ComponentType; diff --git a/types/react-window-size/react-window-size-tests.tsx b/types/react-window-size/react-window-size-tests.tsx new file mode 100644 index 0000000000..b16ebf1eea --- /dev/null +++ b/types/react-window-size/react-window-size-tests.tsx @@ -0,0 +1,23 @@ +import * as React from 'react'; +import windowSize, { WindowSizeProps } from 'react-window-size'; + +interface TestProps { + foo: string; +} + +type TestInnerProps = TestProps & WindowSizeProps; + +const TestComponent: React.ComponentType = ({ foo, windowHeight, windowWidth }) => { + foo; // $ExpectType string + windowHeight; // $ExpectType number + windowWidth; // $ExpectType number + return ( +
+

Foo: {foo}

+

Window height: {windowHeight}

+

Window width: {windowWidth}

+
+ ); +}; + +windowSize(TestComponent); // $ExpectType ComponentType diff --git a/types/react-window-size/tsconfig.json b/types/react-window-size/tsconfig.json new file mode 100644 index 0000000000..46f5b105dd --- /dev/null +++ b/types/react-window-size/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true, + "strictFunctionTypes": true, + "jsx": "react" + }, + "files": [ + "index.d.ts", + "react-window-size-tests.tsx" + ] +} diff --git a/types/react-window-size/tslint.json b/types/react-window-size/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/react-window-size/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }