Implement our own Ref type

So that we do not need a dependency on @types/react.
This commit is contained in:
Andrew Huth
2019-04-04 15:22:33 -07:00
parent ad2991c7dd
commit fd35129019
2 changed files with 8 additions and 3 deletions
@@ -152,7 +152,7 @@ AirbnbPropTypes.range(0, 10);
// $ExpectType Requireable<5>
AirbnbPropTypes.range<5>(0, 10);
// $ExpectType Requireable<LegacyRef<HTMLElement>>
// $ExpectType Requireable<ReactLegacyRefLike<HTMLElement>>
AirbnbPropTypes.ref();
// $ExpectType Requireable<string | null>
+7 -2
View File
@@ -5,7 +5,6 @@
// TypeScript Version: 3.0
import * as PropTypes from 'prop-types';
import * as React from 'react';
export interface ReactComponentLike {
setState(...args: any[]): any;
@@ -25,6 +24,12 @@ export type ReactFunctionComponentLike = (...args: any[]) => PropTypes.ReactNode
export type ReactTypeLike = string | ReactClassComponentLike | ReactFunctionComponentLike;
export interface ReactRefLike<T> {
readonly current: T | null;
}
export type ReactLegacyRefLike<T> = (instance: T | null) => void | ReactRefLike<T> | null;
export interface Specifier<T = any> {
max?: number;
min?: number;
@@ -157,7 +162,7 @@ export function range<T extends number>(min?: number, max?: number): PropTypes.R
export function range(min?: number, max?: number): PropTypes.Requireable<number>;
export function ref(): PropTypes.Requireable<React.LegacyRef<HTMLElement>>;
export function ref(): PropTypes.Requireable<ReactLegacyRefLike<HTMLElement>>;
export function requiredBy<P>(
requiredByPropName: string,