diff --git a/types/react-hot-loader/index.d.ts b/types/react-hot-loader/index.d.ts index 6443fd1f43..ccae5a929c 100644 --- a/types/react-hot-loader/index.d.ts +++ b/types/react-hot-loader/index.d.ts @@ -1,19 +1,25 @@ -// Type definitions for react-hot-loader 3.0 +// Type definitions for react-hot-loader 4.1 // Project: https://github.com/gaearon/react-hot-loader // Definitions by: Jacek Jagiello +// MartynasZilinskas +// Dovydas Navickas // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.6 +// TypeScript Version: 2.8 -import * as React from "react" +import * as React from "react"; +import "node"; -interface ErrorReporterProps { - error: any +export type ReactComponent = React.ComponentClass | React.StatelessComponent; +export type ExtractProps = TComponent extends ReactComponent ? TProps : {}; + +export interface ErrorReporterProps { + error: any; } export interface AppContainerProps { - children?: React.ReactElement, - errorReporter?: React.ComponentClass | React.StatelessComponent - warnings?: boolean + errorReporter?: ReactComponent; + warnings?: boolean; } - export class AppContainer extends React.Component {} + +export function hot(sourceModule: NodeModule): (component: TComponent) => ReactComponent>; diff --git a/types/react-hot-loader/react-hot-loader-tests.tsx b/types/react-hot-loader/react-hot-loader-tests.tsx index 771f4fdd26..ad5b9cc686 100644 --- a/types/react-hot-loader/react-hot-loader-tests.tsx +++ b/types/react-hot-loader/react-hot-loader-tests.tsx @@ -1,29 +1,59 @@ -import * as React from 'react' -import { AppContainer } from 'react-hot-loader' +import * as React from "react"; +import { AppContainer, hot, ReactComponent } from "react-hot-loader"; -interface ErrorReporterProps { - error: any -} +declare function describe(desc: string, f: () => void): void; +declare function it(desc: string, f: () => void): void; -class ErrorReporterComponent extends React.Component { - public render() { - return

{this.props.error.message}

- } -} +it("Using AppContainer", () => { + interface ErrorReporterProps { + error: any; + } -const DummyComponent = () =>

Dummy component

-const ErrorReporter = ({ error } : ErrorReporterProps) => + class ErrorReporterComponent extends React.Component { + render() { + return

{this.props.error.message}

; + } + } -class AppContainerTest extends React.Component { - public render() { - return ( -
- - - -
- ) - } -} + const DummyComponent = () =>

Dummy component

; + const ErrorReporter = ({ error }: ErrorReporterProps) => ; -export default AppContainerTest + class AppContainerTest extends React.Component { + render() { + return ( +
+ + + +
+ ); + } + } +}); + +it("Using hot", () => { + interface Props { + name: string; + } + + class Foo extends React.Component { + render(): JSX.Element { + return
Foo
; + } + } + const FooSFC = (props: { surname: string }) => { + return
; + }; + + const Bar = hot(module)(Foo); + const BarSFC = hot(module)(FooSFC); + + const testRender = () => { + return ( + <> + + + + ); + }; +}); diff --git a/types/react-hot-loader/tsconfig.json b/types/react-hot-loader/tsconfig.json index 5e898cb303..30206811ef 100644 --- a/types/react-hot-loader/tsconfig.json +++ b/types/react-hot-loader/tsconfig.json @@ -22,4 +22,4 @@ "index.d.ts", "react-hot-loader-tests.tsx" ] -} \ No newline at end of file +} diff --git a/types/react-hot-loader/tslint.json b/types/react-hot-loader/tslint.json index a41bf5d19a..3db14f85ea 100644 --- a/types/react-hot-loader/tslint.json +++ b/types/react-hot-loader/tslint.json @@ -1,79 +1 @@ -{ - "extends": "dtslint/dt.json", - "rules": { - "adjacent-overload-signatures": false, - "array-type": false, - "arrow-return-shorthand": false, - "ban-types": false, - "callable-types": false, - "comment-format": false, - "dt-header": false, - "eofline": false, - "export-just-namespace": false, - "import-spacing": false, - "interface-name": false, - "interface-over-type-literal": false, - "jsdoc-format": false, - "max-line-length": false, - "member-access": false, - "new-parens": false, - "no-any-union": false, - "no-boolean-literal-compare": false, - "no-conditional-assignment": false, - "no-consecutive-blank-lines": false, - "no-construct": false, - "no-declare-current-package": false, - "no-duplicate-imports": false, - "no-duplicate-variable": false, - "no-empty-interface": false, - "no-for-in-array": false, - "no-inferrable-types": false, - "no-internal-module": false, - "no-irregular-whitespace": false, - "no-mergeable-namespace": false, - "no-misused-new": false, - "no-namespace": false, - "no-object-literal-type-assertion": false, - "no-padding": false, - "no-redundant-jsdoc": false, - "no-redundant-jsdoc-2": false, - "no-redundant-undefined": false, - "no-reference-import": false, - "no-relative-import-in-test": false, - "no-self-import": false, - "no-single-declare-module": false, - "no-string-throw": false, - "no-unnecessary-callback-wrapper": false, - "no-unnecessary-class": false, - "no-unnecessary-generics": false, - "no-unnecessary-qualifier": false, - "no-unnecessary-type-assertion": false, - "no-useless-files": false, - "no-var-keyword": false, - "no-var-requires": false, - "no-void-expression": false, - "no-trailing-whitespace": false, - "object-literal-key-quotes": false, - "object-literal-shorthand": false, - "one-line": false, - "one-variable-per-declaration": false, - "only-arrow-functions": false, - "prefer-conditional-expression": false, - "prefer-const": false, - "prefer-declare-function": false, - "prefer-for-of": false, - "prefer-method-signature": false, - "prefer-template": false, - "radix": false, - "semicolon": false, - "space-before-function-paren": false, - "space-within-parens": false, - "strict-export-declare-modifiers": false, - "trim-file": false, - "triple-equals": false, - "typedef-whitespace": false, - "unified-signatures": false, - "void-return": false, - "whitespace": false - } -} +{ "extends": "dtslint/dt.json" }