From 939bed73a7d34dd52065ae66b6df36c7f2152f3c Mon Sep 17 00:00:00 2001 From: Ivan Zub Date: Fri, 5 Oct 2018 20:29:26 +0200 Subject: [PATCH] Add type definitions for airbnb/react-outside-click-handler (#29471) * Add type definitions for react-outside-click-handler * Fix tests and fallback to TS 2.9 DT is not supporting typescript 3 yet, so can't properly use defaultProps --- types/react-outside-click-handler/index.d.ts | 23 ++++++++++++++++++ .../react-outside-click-handler-tests.tsx | 21 ++++++++++++++++ .../react-outside-click-handler/tsconfig.json | 24 +++++++++++++++++++ types/react-outside-click-handler/tslint.json | 3 +++ 4 files changed, 71 insertions(+) create mode 100644 types/react-outside-click-handler/index.d.ts create mode 100644 types/react-outside-click-handler/test/react-outside-click-handler-tests.tsx create mode 100644 types/react-outside-click-handler/tsconfig.json create mode 100644 types/react-outside-click-handler/tslint.json diff --git a/types/react-outside-click-handler/index.d.ts b/types/react-outside-click-handler/index.d.ts new file mode 100644 index 0000000000..470e2c3657 --- /dev/null +++ b/types/react-outside-click-handler/index.d.ts @@ -0,0 +1,23 @@ +// Type definitions for react-outside-click-handler 1.2 +// Project: https://github.com/airbnb/react-outside-click-handler +// Definitions by: Ivan Zub +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.9 + +import * as React from "react"; + +export interface DefaultProps { + disabled: boolean; + useCapture: boolean; + display: "block" | "flex" | "inline-block"; +} + +// TODO: Remove partial once DT support TS 3.0, so skipping mandatory listed in default props won't result in compile error +export interface Props extends Partial { + children: React.ReactNode; + onOutsideClick: (e: React.MouseEvent) => void; +} + +export default class OutsideClickHandler extends React.Component { + static defaultProps: DefaultProps; +} diff --git a/types/react-outside-click-handler/test/react-outside-click-handler-tests.tsx b/types/react-outside-click-handler/test/react-outside-click-handler-tests.tsx new file mode 100644 index 0000000000..116cabcf56 --- /dev/null +++ b/types/react-outside-click-handler/test/react-outside-click-handler-tests.tsx @@ -0,0 +1,21 @@ +import * as React from "react"; + +import OutsideClickHandler from "react-outside-click-handler"; + +const onClickOutside: (event: React.MouseEvent) => void = () => {}; + + + Child +; + + + Child +; + + + Child +; + + + Child +; diff --git a/types/react-outside-click-handler/tsconfig.json b/types/react-outside-click-handler/tsconfig.json new file mode 100644 index 0000000000..4121effb03 --- /dev/null +++ b/types/react-outside-click-handler/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "jsx": "react", + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "test/react-outside-click-handler-tests.tsx" + ] +} diff --git a/types/react-outside-click-handler/tslint.json b/types/react-outside-click-handler/tslint.json new file mode 100644 index 0000000000..f93cf8562a --- /dev/null +++ b/types/react-outside-click-handler/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dt.json" +}