@types/react 16.8.1 → 16.8.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. react/README.md +1 -1
  2. react/index.d.ts +44 -17
  3. react/package.json +4 -3
react/README.md CHANGED
@@ -8,7 +8,7 @@ This package contains type definitions for React ( http://facebook.github.io/rea
8
8
  Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/react
9
9
 
10
10
  Additional Details
11
- * Last updated: Fri, 01 Feb 2019 22:16:14 GMT
11
+ * Last updated: Mon, 25 Feb 2019 23:06:26 GMT
12
12
  * Dependencies: @types/csstype, @types/prop-types
13
13
  * Global values: React
14
14
 
react/index.d.ts CHANGED
@@ -59,7 +59,7 @@ declare namespace React {
59
59
  type ComponentType<P = {}> = ComponentClass<P> | FunctionComponent<P>;
60
60
 
61
61
  type JSXElementConstructor<P> =
62
- | ((props: P) => ReactElement<any> | null)
62
+ | ((props: P) => ReactElement | null)
63
63
  | (new (props: P) => Component<P, any>);
64
64
 
65
65
  type Key = string | number;
@@ -83,7 +83,7 @@ declare namespace React {
83
83
  ref?: LegacyRef<T>;
84
84
  }
85
85
 
86
- interface ReactElement<P, T extends string | JSXElementConstructor<any> = string | JSXElementConstructor<any>> {
86
+ interface ReactElement<P = any, T extends string | JSXElementConstructor<any> = string | JSXElementConstructor<any>> {
87
87
  type: T;
88
88
  props: P;
89
89
  key: Key | null;
@@ -128,7 +128,7 @@ declare namespace React {
128
128
  type: keyof ReactSVG;
129
129
  }
130
130
 
131
- interface ReactPortal extends ReactElement<any> {
131
+ interface ReactPortal extends ReactElement {
132
132
  key: Key | null;
133
133
  children: ReactNode;
134
134
  }
@@ -172,7 +172,7 @@ declare namespace React {
172
172
  // ----------------------------------------------------------------------
173
173
 
174
174
  type ReactText = string | number;
175
- type ReactChild = ReactElement<any> | ReactText;
175
+ type ReactChild = ReactElement | ReactText;
176
176
 
177
177
  interface ReactNodeArray extends Array<ReactNode> {}
178
178
  type ReactFragment = {} | ReactNodeArray;
@@ -297,7 +297,7 @@ declare namespace React {
297
297
  /**
298
298
  * **NOTE**: Exotic components are not callable.
299
299
  */
300
- (props: P): (ReactElement<any>|null);
300
+ (props: P): (ReactElement|null);
301
301
  readonly $$typeof: symbol;
302
302
  }
303
303
 
@@ -422,7 +422,7 @@ declare namespace React {
422
422
  // always pass children as variadic arguments to `createElement`.
423
423
  // In the future, if we can define its call signature conditionally
424
424
  // on the existence of `children` in `P`, then we should remove this.
425
- readonly props: Readonly<{ children?: ReactNode }> & Readonly<P>;
425
+ readonly props: Readonly<PropsWithChildren<P>>;
426
426
  state: Readonly<S>;
427
427
  /**
428
428
  * @deprecated
@@ -468,7 +468,7 @@ declare namespace React {
468
468
  type FC<P = {}> = FunctionComponent<P>;
469
469
 
470
470
  interface FunctionComponent<P = {}> {
471
- (props: P & { children?: ReactNode }, context?: any): ReactElement<any> | null;
471
+ (props: PropsWithChildren<P>, context?: any): ReactElement | null;
472
472
  propTypes?: WeakValidationMap<P>;
473
473
  contextTypes?: ValidationMap<any>;
474
474
  defaultProps?: Partial<P>;
@@ -476,7 +476,7 @@ declare namespace React {
476
476
  }
477
477
 
478
478
  interface RefForwardingComponent<T, P = {}> {
479
- (props: P & { children?: ReactNode }, ref: Ref<T>): ReactElement<any> | null;
479
+ (props: PropsWithChildren<P>, ref: Ref<T>): ReactElement | null;
480
480
  propTypes?: WeakValidationMap<P>;
481
481
  contextTypes?: ValidationMap<any>;
482
482
  defaultProps?: Partial<P>;
@@ -722,6 +722,8 @@ declare namespace React {
722
722
  : P
723
723
  : P;
724
724
 
725
+ type PropsWithChildren<P> = P & { children?: ReactNode };
726
+
725
727
  /**
726
728
  * NOTE: prefer ComponentPropsWithRef, if the ref is forwarded,
727
729
  * or ComponentPropsWithoutRef when refs are not supported.
@@ -747,7 +749,7 @@ declare namespace React {
747
749
 
748
750
  function memo<P extends object>(
749
751
  Component: SFC<P>,
750
- propsAreEqual?: (prevProps: Readonly<P & { children?: ReactNode }>, nextProps: Readonly<P & { children?: ReactNode }>) => boolean
752
+ propsAreEqual?: (prevProps: Readonly<PropsWithChildren<P>>, nextProps: Readonly<PropsWithChildren<P>>) => boolean
751
753
  ): NamedExoticComponent<P>;
752
754
  function memo<T extends ComponentType<any>>(
753
755
  Component: T,
@@ -783,11 +785,9 @@ declare namespace React {
783
785
  // TODO (TypeScript 3.0): ReadonlyArray<unknown>
784
786
  type DependencyList = ReadonlyArray<any>;
785
787
 
786
- // NOTE: Currently, in alpha.0, the effect callbacks are actually allowed to return anything,
787
- // but functions are treated specially. The next version published with hooks will warn if you actually
788
- // return anything besides `void` or a callback. Async effects need to call an async function inside
789
- // them.
790
- type EffectCallback = () => (void | (() => void));
788
+ // NOTE: callbacks are _only_ allowed to return either void, or a destructor.
789
+ // The destructor is itself only allowed to return void.
790
+ type EffectCallback = () => (void | (() => void | undefined));
791
791
 
792
792
  interface MutableRefObject<T> {
793
793
  current: T;
@@ -809,6 +809,14 @@ declare namespace React {
809
809
  * @see https://reactjs.org/docs/hooks-reference.html#usestate
810
810
  */
811
811
  function useState<S>(initialState: S | (() => S)): [S, Dispatch<SetStateAction<S>>];
812
+ // convenience overload when first argument is ommitted
813
+ /**
814
+ * Returns a stateful value, and a function to update it.
815
+ *
816
+ * @version 16.8.0
817
+ * @see https://reactjs.org/docs/hooks-reference.html#usestate
818
+ */
819
+ function useState<S = undefined>(): [S | undefined, Dispatch<SetStateAction<S | undefined>>];
812
820
  /**
813
821
  * An alternative to `useState`.
814
822
  *
@@ -853,12 +861,16 @@ declare namespace React {
853
861
  * @version 16.8.0
854
862
  * @see https://reactjs.org/docs/hooks-reference.html#usereducer
855
863
  */
864
+
856
865
  // I'm not sure if I keep this 2-ary or if I make it (2,3)-ary; it's currently (2,3)-ary.
857
866
  // The Flow types do have an overload for 3-ary invocation with undefined initializer.
858
- // NOTE: the documentation or any alphas aren't updated, this is current for master.
859
- // NOTE 2: without the ReducerState indirection, TypeScript would reduce S to be the most common
867
+
868
+ // NOTE: without the ReducerState indirection, TypeScript would reduce S to be the most common
860
869
  // supertype between the reducer's return type and the initialState (or the initializer's return type),
861
870
  // which would prevent autocompletion from ever working.
871
+
872
+ // TODO: double-check if this weird overload logic is necessary. It is possible it's either a bug
873
+ // in older versions, or a regression in newer versions of the typescript completion service.
862
874
  function useReducer<R extends Reducer<any, any>>(
863
875
  reducer: R,
864
876
  initialState: ReducerState<R>,
@@ -892,6 +904,20 @@ declare namespace React {
892
904
  */
893
905
  // TODO (TypeScript 3.0): <T extends unknown>
894
906
  function useRef<T>(initialValue: T|null): RefObject<T>;
907
+ // convenience overload for potentially undefined initialValue / call with 0 arguments
908
+ // has a default to stop it from defaulting to {} instead
909
+ /**
910
+ * `useRef` returns a mutable ref object whose `.current` property is initialized to the passed argument
911
+ * (`initialValue`). The returned object will persist for the full lifetime of the component.
912
+ *
913
+ * Note that `useRef()` is useful for more than the `ref` attribute. It’s handy for keeping any mutable
914
+ * value around similar to how you’d use instance fields in classes.
915
+ *
916
+ * @version 16.8.0
917
+ * @see https://reactjs.org/docs/hooks-reference.html#useref
918
+ */
919
+ // TODO (TypeScript 3.0): <T extends unknown>
920
+ function useRef<T = undefined>(): MutableRefObject<T | undefined>;
895
921
  /**
896
922
  * The signature is identical to `useEffect`, but it fires synchronously after all DOM mutations.
897
923
  * Use this to read layout from the DOM and synchronously re-render. Updates scheduled inside
@@ -956,7 +982,8 @@ declare namespace React {
956
982
  * @version 16.8.0
957
983
  * @see https://reactjs.org/docs/hooks-reference.html#usememo
958
984
  */
959
- function useMemo<T>(factory: () => T, deps: DependencyList): T;
985
+ // allow undefined, but don't make it optional as that is very likely a mistake
986
+ function useMemo<T>(factory: () => T, deps: DependencyList | undefined): T;
960
987
  /**
961
988
  * `useDebugValue` can be used to display a label for custom hooks in React DevTools.
962
989
  *
react/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@types/react",
3
- "version": "16.8.1",
3
+ "version": "16.8.5",
4
4
  "description": "TypeScript definitions for React",
5
5
  "license": "MIT",
6
6
  "contributors": [
@@ -111,13 +111,14 @@
111
111
  "types": "index",
112
112
  "repository": {
113
113
  "type": "git",
114
- "url": "https://github.com/DefinitelyTyped/DefinitelyTyped.git"
114
+ "url": "https://github.com/DefinitelyTyped/DefinitelyTyped.git",
115
+ "directory": "types/react"
115
116
  },
116
117
  "scripts": {},
117
118
  "dependencies": {
118
119
  "@types/prop-types": "*",
119
120
  "csstype": "^2.2.0"
120
121
  },
121
- "typesPublisherContentHash": "5e6c26eca19df3467cf389dc97a7d83025def98e1e1d0472fc639ca41afa8ac0",
122
+ "typesPublisherContentHash": "c1110ffd4d8413625cd4a49f91896ff4bdf7a89150082135075687ed9b9dd0da",
122
123
  "typeScriptVersion": "2.8"
123
124
  }