From ba12fade9c56f0b48b3a73e1f44014fdf05ba154 Mon Sep 17 00:00:00 2001 From: Sean Kelley Date: Wed, 29 Jun 2016 11:07:36 -0700 Subject: [PATCH] Add typings for react-is-deprecated. --- .../react-is-deprecated-tests.ts | 17 +++++++++ react-is-deprecated/react-is-deprecated.d.ts | 38 +++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 react-is-deprecated/react-is-deprecated-tests.ts create mode 100644 react-is-deprecated/react-is-deprecated.d.ts diff --git a/react-is-deprecated/react-is-deprecated-tests.ts b/react-is-deprecated/react-is-deprecated-tests.ts new file mode 100644 index 0000000000..f5574e44cf --- /dev/null +++ b/react-is-deprecated/react-is-deprecated-tests.ts @@ -0,0 +1,17 @@ +/// +/// + +import { PropTypes } from 'react'; +import { deprecate, addIsDeprecated } from 'react-is-deprecated'; + +// test: one-off deprecation +deprecate(PropTypes.string, 'message'); + +// test: one-off deprecated with isRequired +deprecate(PropTypes.string.isRequired, 'message'); + +// test: isDeprecated is added to a proptype +addIsDeprecated(PropTypes).string.isDeprecated('message'); + +// test: isRequired is still present on that proptype +addIsDeprecated(PropTypes).string.isRequired; diff --git a/react-is-deprecated/react-is-deprecated.d.ts b/react-is-deprecated/react-is-deprecated.d.ts new file mode 100644 index 0000000000..88a34306a5 --- /dev/null +++ b/react-is-deprecated/react-is-deprecated.d.ts @@ -0,0 +1,38 @@ +// Type definitions for react-is-deprecated v0.1.2 +// Project: https://github.com/Aweary/react-is-deprecated +// Definitions by: Sean Kelley +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +declare module 'react-is-deprecated' { + import { Validator, Requireable, ValidationMap, ReactPropTypes } from 'react'; + + export function deprecate(validator: Validator, message: string): Validator; + + interface Deprecatable { + isDeprecated: (message: string) => Validator; + } + + // Unfortunately this copy-paste must happen -- I can't just take PropTypes and programmatically + // define a version that intersects in the Deprecatable interface into the keys. + interface DeprecatablePropTypes { + any: Requireable & Deprecatable; + array: Requireable & Deprecatable; + bool: Requireable & Deprecatable; + func: Requireable & Deprecatable; + number: Requireable & Deprecatable; + object: Requireable & Deprecatable; + string: Requireable & Deprecatable; + node: Requireable & Deprecatable; + element: Requireable & Deprecatable; + instanceOf(expectedClass: {}): Requireable & Deprecatable; + oneOf(types: any[]): Requireable & Deprecatable; + oneOfType(types: Validator[]): Requireable & Deprecatable; + arrayOf(type: Validator): Requireable & Deprecatable; + objectOf(type: Validator): Requireable & Deprecatable; + shape(type: ValidationMap): Requireable & Deprecatable; + } + + export function addIsDeprecated(propTypes: ReactPropTypes): DeprecatablePropTypes; +}