From 85762b3be6dc2c0179d9d0bb299f5e5b8096d371 Mon Sep 17 00:00:00 2001 From: Eirikur Nilsson Date: Wed, 16 Aug 2017 19:45:33 +0000 Subject: [PATCH] Fix callbacks in react-portal and react-sidebar This is a common pitfall when writing definitions. See discussion here: https://github.com/DefinitelyTyped/DefinitelyTyped/pull/15526#issuecomment-322781094 --- types/react-portal/index.d.ts | 10 ++++---- types/react-portal/react-portal-tests.tsx | 26 +++++++++++++++------ types/react-sidebar/index.d.ts | 2 +- types/react-sidebar/react-sidebar-tests.tsx | 14 ++++++++--- 4 files changed, 36 insertions(+), 16 deletions(-) diff --git a/types/react-portal/index.d.ts b/types/react-portal/index.d.ts index 48d26f8d1b..ee6a5c857f 100644 --- a/types/react-portal/index.d.ts +++ b/types/react-portal/index.d.ts @@ -7,7 +7,7 @@ import * as React from "react"; interface CallBackProps extends React.Props { - closePortal(): {}; + closePortal(): void; } interface ReactPortalProps { @@ -15,10 +15,10 @@ interface ReactPortalProps { openByClickOn?: React.ReactElement; closeOnEsc?: boolean; closeOnOutsideClick?: boolean; - onOpen?(node: HTMLDivElement): {}; - beforeClose?(node: HTMLDivElement, resetPortalState: () => void): {}; - onClose?(): {}; - onUpdate?(): {}; + onOpen?(node: HTMLDivElement): void; + beforeClose?(node: HTMLDivElement, resetPortalState: () => void): void; + onClose?(): void; + onUpdate?(): void; } declare const ReactPortal: React.ComponentClass; diff --git a/types/react-portal/react-portal-tests.tsx b/types/react-portal/react-portal-tests.tsx index 08d730dcf5..ca6c0289de 100644 --- a/types/react-portal/react-portal-tests.tsx +++ b/types/react-portal/react-portal-tests.tsx @@ -8,17 +8,29 @@ export default class App extends React.Component { const button1 = ; return ( - - -

Pseudo Modal

-

This react component is appended to the document body.

-
-
+
+ {}} + beforeClose={(node: HTMLDivElement, resetPortalState) => resetPortalState()} + onClose={() => {}} + onUpdate={() => {}} + > + +

Pseudo Modal

+

This react component is appended to the document body.

+
+
+ +
); } } -export class PseudoModal extends React.Component<{ closePortal?(): {} }> { +export class PseudoModal extends React.Component<{ closePortal?(): void }> { render() { return (
diff --git a/types/react-sidebar/index.d.ts b/types/react-sidebar/index.d.ts index b73863a079..9701c09d78 100644 --- a/types/react-sidebar/index.d.ts +++ b/types/react-sidebar/index.d.ts @@ -10,7 +10,7 @@ export interface SidebarProps { contentClassName?: string; docked?: boolean; dragToggleDistance?: number; - onSetOpen?(): {}; + onSetOpen?(): void; open?: boolean; overlayClassName?: string; pullRight?: boolean; diff --git a/types/react-sidebar/react-sidebar-tests.tsx b/types/react-sidebar/react-sidebar-tests.tsx index 4b6dfd593e..491bd3fb4f 100644 --- a/types/react-sidebar/react-sidebar-tests.tsx +++ b/types/react-sidebar/react-sidebar-tests.tsx @@ -7,6 +7,14 @@ const sidebarStyle: SidebarStyles = { content: { width: "300px" } }; -const sidebar1 = -

Content

-
; +const sidebar1 = ( + {}} + > +

Content

+
+);