add type definitions for react-sizes (#36058)

* add type definitions for react-sizes

* conform Definitions by: to expected format

* test file extension is .tsx, not .ts

* specify typescript version in header, remove old comment

* "strictFunctionTypes": true,  to satisfy the CI gods

* make testProp foo optional

* add "jsx": "react" compiler option

* change TestInnerProps to an interface, update expectation for foo

* add type definitions for react-sizes

* conform Definitions by: to expected format

* test file extension is .tsx, not .ts

* specify typescript version in header, remove old comment

* "strictFunctionTypes": true,  to satisfy the CI gods

* make testProp foo optional

* add "jsx": "react" compiler option

* change TestInnerProps to an interface, update expectation for foo

* fix example in test

* remove trailing white space.  change TestProps from interface to Type

* use interface instead

* explicit exports

* specify return type in test example

* add type definitions for react-sizes

* conform Definitions by: to expected format

* test file extension is .tsx, not .ts

* specify typescript version in header, remove old comment

* "strictFunctionTypes": true,  to satisfy the CI gods

* make testProp foo optional

* add "jsx": "react" compiler option

* change TestInnerProps to an interface, update expectation for foo

* add type definitions for react-sizes

* fix example in test

* remove trailing white space.  change TestProps from interface to Type

* use interface instead

* explicit exports

* specify return type in test example

* use PascalCase for type names

* PascalCase for MapSizesToProps

* inline type for mapSizesToProps function

* fix import

* remove errant ;

* remove lib compiler option in tsconfig

* Revert "remove lib compiler option in tsconfig"

This reverts commit 97d100788581e2bfacc563d676af4ad3020a68a1.

* export WithSizes as default and import it as default in test.  retain named export of WithSizes to match react-sizes library's export pattern
This commit is contained in:
Micah Stubbs 2019-07-09 12:56:58 -07:00 committed by Armando Aguirre
parent 26587aa3aa
commit 6317726538
4 changed files with 70 additions and 0 deletions

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

@ -0,0 +1,16 @@
// Type definitions for react-sizes 2.0
// Project: https://github.com/renatorib/react-sizes#readme
// Definitions by: janKir <https://github.com/janKir>, Micah Stubbs <https://github.com/micahstubbs>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 3.5
export interface Sizes {
width: number;
height: number;
}
export function WithSizes<SP extends object, P extends SP>(
mapSizesToProps: (sizes: Sizes) => SP
): (component: React.ComponentType<P>) => React.ComponentType<P>;
export default WithSizes;

View File

@ -0,0 +1,29 @@
import * as React from 'react';
import WithSizes, { Sizes } from 'react-sizes';
interface TestProps {
foo: string;
width: number;
height: number;
}
const mapSizesToProps = ({ width, height }: Sizes): TestProps => ({
foo: 'foo',
width,
height,
});
const TestComponent: React.ComponentType<TestProps> = ({ foo, width, height }) => {
foo; // $ExpectType string
width; // $ExpectType number
height; // $ExpectType number
return (
<div>
<p>Foo: {foo}</p>
<p>Window width: {width}</p>
<p>Window height: {height}</p>
</div>
);
};
WithSizes(mapSizesToProps)(TestComponent); // $ExpectType ComponentType<TestProps>

View File

@ -0,0 +1,24 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true,
"jsx": "react"
},
"files": [
"index.d.ts",
"react-sizes-tests.tsx"
]
}

View File

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