@types/react 16.8.2 → 16.8.6

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 +42 -13
  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: Wed, 06 Feb 2019 12:44:09 GMT
11
+ * Last updated: Thu, 28 Feb 2019 18:34:58 GMT
12
12
  * Dependencies: @types/csstype, @types/prop-types
13
13
  * Global values: React
14
14
 
react/index.d.ts CHANGED
@@ -51,15 +51,19 @@ declare namespace React {
51
51
  // React Elements
52
52
  // ----------------------------------------------------------------------
53
53
 
54
- type ReactType<P = any> =
54
+ type ElementType<P = any> =
55
55
  {
56
56
  [K in keyof JSX.IntrinsicElements]: P extends JSX.IntrinsicElements[K] ? K : never
57
57
  }[keyof JSX.IntrinsicElements] |
58
58
  ComponentType<P>;
59
+ /**
60
+ * @deprecated Please use `ElementType`
61
+ */
62
+ type ReactType<P = any> = ElementType<P>;
59
63
  type ComponentType<P = {}> = ComponentClass<P> | FunctionComponent<P>;
60
64
 
61
65
  type JSXElementConstructor<P> =
62
- | ((props: P) => ReactElement<any> | null)
66
+ | ((props: P) => ReactElement | null)
63
67
  | (new (props: P) => Component<P, any>);
64
68
 
65
69
  type Key = string | number;
@@ -83,7 +87,7 @@ declare namespace React {
83
87
  ref?: LegacyRef<T>;
84
88
  }
85
89
 
86
- interface ReactElement<P, T extends string | JSXElementConstructor<any> = string | JSXElementConstructor<any>> {
90
+ interface ReactElement<P = any, T extends string | JSXElementConstructor<any> = string | JSXElementConstructor<any>> {
87
91
  type: T;
88
92
  props: P;
89
93
  key: Key | null;
@@ -128,7 +132,7 @@ declare namespace React {
128
132
  type: keyof ReactSVG;
129
133
  }
130
134
 
131
- interface ReactPortal extends ReactElement<any> {
135
+ interface ReactPortal extends ReactElement {
132
136
  key: Key | null;
133
137
  children: ReactNode;
134
138
  }
@@ -172,7 +176,7 @@ declare namespace React {
172
176
  // ----------------------------------------------------------------------
173
177
 
174
178
  type ReactText = string | number;
175
- type ReactChild = ReactElement<any> | ReactText;
179
+ type ReactChild = ReactElement | ReactText;
176
180
 
177
181
  interface ReactNodeArray extends Array<ReactNode> {}
178
182
  type ReactFragment = {} | ReactNodeArray;
@@ -297,7 +301,7 @@ declare namespace React {
297
301
  /**
298
302
  * **NOTE**: Exotic components are not callable.
299
303
  */
300
- (props: P): (ReactElement<any>|null);
304
+ (props: P): (ReactElement|null);
301
305
  readonly $$typeof: symbol;
302
306
  }
303
307
 
@@ -422,7 +426,7 @@ declare namespace React {
422
426
  // always pass children as variadic arguments to `createElement`.
423
427
  // In the future, if we can define its call signature conditionally
424
428
  // on the existence of `children` in `P`, then we should remove this.
425
- readonly props: Readonly<{ children?: ReactNode }> & Readonly<P>;
429
+ readonly props: Readonly<PropsWithChildren<P>>;
426
430
  state: Readonly<S>;
427
431
  /**
428
432
  * @deprecated
@@ -468,7 +472,7 @@ declare namespace React {
468
472
  type FC<P = {}> = FunctionComponent<P>;
469
473
 
470
474
  interface FunctionComponent<P = {}> {
471
- (props: P & { children?: ReactNode }, context?: any): ReactElement<any> | null;
475
+ (props: PropsWithChildren<P>, context?: any): ReactElement | null;
472
476
  propTypes?: WeakValidationMap<P>;
473
477
  contextTypes?: ValidationMap<any>;
474
478
  defaultProps?: Partial<P>;
@@ -476,7 +480,7 @@ declare namespace React {
476
480
  }
477
481
 
478
482
  interface RefForwardingComponent<T, P = {}> {
479
- (props: P & { children?: ReactNode }, ref: Ref<T>): ReactElement<any> | null;
483
+ (props: PropsWithChildren<P>, ref: Ref<T>): ReactElement | null;
480
484
  propTypes?: WeakValidationMap<P>;
481
485
  contextTypes?: ValidationMap<any>;
482
486
  defaultProps?: Partial<P>;
@@ -722,6 +726,8 @@ declare namespace React {
722
726
  : P
723
727
  : P;
724
728
 
729
+ type PropsWithChildren<P> = P & { children?: ReactNode };
730
+
725
731
  /**
726
732
  * NOTE: prefer ComponentPropsWithRef, if the ref is forwarded,
727
733
  * or ComponentPropsWithoutRef when refs are not supported.
@@ -732,11 +738,11 @@ declare namespace React {
732
738
  : T extends keyof JSX.IntrinsicElements
733
739
  ? JSX.IntrinsicElements[T]
734
740
  : {};
735
- type ComponentPropsWithRef<T extends ReactType> =
741
+ type ComponentPropsWithRef<T extends ElementType> =
736
742
  T extends ComponentClass<infer P>
737
743
  ? PropsWithoutRef<P> & RefAttributes<InstanceType<T>>
738
744
  : PropsWithRef<ComponentProps<T>>;
739
- type ComponentPropsWithoutRef<T extends ReactType> =
745
+ type ComponentPropsWithoutRef<T extends ElementType> =
740
746
  PropsWithoutRef<ComponentProps<T>>;
741
747
 
742
748
  // will show `Memo(${Component.displayName || Component.name})` in devtools by default,
@@ -747,7 +753,7 @@ declare namespace React {
747
753
 
748
754
  function memo<P extends object>(
749
755
  Component: SFC<P>,
750
- propsAreEqual?: (prevProps: Readonly<P & { children?: ReactNode }>, nextProps: Readonly<P & { children?: ReactNode }>) => boolean
756
+ propsAreEqual?: (prevProps: Readonly<PropsWithChildren<P>>, nextProps: Readonly<PropsWithChildren<P>>) => boolean
751
757
  ): NamedExoticComponent<P>;
752
758
  function memo<T extends ComponentType<any>>(
753
759
  Component: T,
@@ -807,6 +813,14 @@ declare namespace React {
807
813
  * @see https://reactjs.org/docs/hooks-reference.html#usestate
808
814
  */
809
815
  function useState<S>(initialState: S | (() => S)): [S, Dispatch<SetStateAction<S>>];
816
+ // convenience overload when first argument is ommitted
817
+ /**
818
+ * Returns a stateful value, and a function to update it.
819
+ *
820
+ * @version 16.8.0
821
+ * @see https://reactjs.org/docs/hooks-reference.html#usestate
822
+ */
823
+ function useState<S = undefined>(): [S | undefined, Dispatch<SetStateAction<S | undefined>>];
810
824
  /**
811
825
  * An alternative to `useState`.
812
826
  *
@@ -894,6 +908,20 @@ declare namespace React {
894
908
  */
895
909
  // TODO (TypeScript 3.0): <T extends unknown>
896
910
  function useRef<T>(initialValue: T|null): RefObject<T>;
911
+ // convenience overload for potentially undefined initialValue / call with 0 arguments
912
+ // has a default to stop it from defaulting to {} instead
913
+ /**
914
+ * `useRef` returns a mutable ref object whose `.current` property is initialized to the passed argument
915
+ * (`initialValue`). The returned object will persist for the full lifetime of the component.
916
+ *
917
+ * Note that `useRef()` is useful for more than the `ref` attribute. It’s handy for keeping any mutable
918
+ * value around similar to how you’d use instance fields in classes.
919
+ *
920
+ * @version 16.8.0
921
+ * @see https://reactjs.org/docs/hooks-reference.html#useref
922
+ */
923
+ // TODO (TypeScript 3.0): <T extends unknown>
924
+ function useRef<T = undefined>(): MutableRefObject<T | undefined>;
897
925
  /**
898
926
  * The signature is identical to `useEffect`, but it fires synchronously after all DOM mutations.
899
927
  * Use this to read layout from the DOM and synchronously re-render. Updates scheduled inside
@@ -958,7 +986,8 @@ declare namespace React {
958
986
  * @version 16.8.0
959
987
  * @see https://reactjs.org/docs/hooks-reference.html#usememo
960
988
  */
961
- function useMemo<T>(factory: () => T, deps: DependencyList): T;
989
+ // allow undefined, but don't make it optional as that is very likely a mistake
990
+ function useMemo<T>(factory: () => T, deps: DependencyList | undefined): T;
962
991
  /**
963
992
  * `useDebugValue` can be used to display a label for custom hooks in React DevTools.
964
993
  *
react/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@types/react",
3
- "version": "16.8.2",
3
+ "version": "16.8.6",
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": "130eebdadfd2a026860f6d17e74bbbf89e7a2dfc29f96d0f506672fa67c1e175",
122
+ "typesPublisherContentHash": "e0bac5fa4fa2eda491c0e39dee87312b3907670d76b8d32168002822578bfaa1",
122
123
  "typeScriptVersion": "2.8"
123
124
  }