Adding types for react-window-size (#29507)

This commit is contained in:
Jake Richards 2018-10-08 12:17:54 -04:00 committed by Andy
parent d694e947c2
commit d8ca2bf318
4 changed files with 64 additions and 0 deletions

16
types/react-window-size/index.d.ts vendored Normal file
View File

@ -0,0 +1,16 @@
// Type definitions for react-window-size 1.2
// Project: https://github.com/finnfiddle/react-window-size
// Definitions by: Jake Richards <https://github.com/jakejrichards>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8
import { ComponentType } from 'react';
export interface WindowSizeProps {
windowHeight: number;
windowWidth: number;
}
export default function<T>(
ComposedComponent: ComponentType<T & WindowSizeProps>,
): ComponentType<T>;

View File

@ -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<TestInnerProps> = ({ foo, windowHeight, windowWidth }) => {
foo; // $ExpectType string
windowHeight; // $ExpectType number
windowWidth; // $ExpectType number
return (
<div>
<p>Foo: {foo}</p>
<p>Window height: {windowHeight}</p>
<p>Window width: {windowWidth}</p>
</div>
);
};
windowSize(TestComponent); // $ExpectType ComponentType<TestProps>

View File

@ -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"
]
}

View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }