@types/react 16.7.20 → 16.8.1

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 +3 -3
  2. react/index.d.ts +106 -44
  3. react/package.json +9 -4
react/README.md CHANGED
@@ -2,15 +2,15 @@
2
2
  > `npm install --save @types/react`
3
3
 
4
4
  # Summary
5
- This package contains type definitions for React (http://facebook.github.io/react/).
5
+ This package contains type definitions for React ( http://facebook.github.io/react/ ).
6
6
 
7
7
  # Details
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, 16 Jan 2019 13:56:13 GMT
11
+ * Last updated: Fri, 01 Feb 2019 22:16:14 GMT
12
12
  * Dependencies: @types/csstype, @types/prop-types
13
13
  * Global values: React
14
14
 
15
15
  # Credits
16
- These definitions were written by Asana <https://asana.com>, AssureSign <http://www.assuresign.com>, Microsoft <https://microsoft.com>, John Reilly <https://github.com/johnnyreilly>, Benoit Benezech <https://github.com/bbenezech>, Patricio Zavolinsky <https://github.com/pzavolinsky>, Digiguru <https://github.com/digiguru>, Eric Anderson <https://github.com/ericanderson>, Tanguy Krotoff <https://github.com/tkrotoff>, Dovydas Navickas <https://github.com/DovydasNavickas>, Stéphane Goetz <https://github.com/onigoetz>, Josh Rutherford <https://github.com/theruther4d>, Guilherme Hübner <https://github.com/guilhermehubner>, Ferdy Budhidharma <https://github.com/ferdaber>, Johann Rakotoharisoa <https://github.com/jrakotoharisoa>, Olivier Pascal <https://github.com/pascaloliv>, Martin Hochel <https://github.com/hotell>, Frank Li <https://github.com/franklixuefei>, Jessica Franco <https://github.com/Kovensky>, Paul Sherman <https://github.com/pshrmn>.
16
+ These definitions were written by Asana <https://asana.com>, AssureSign <http://www.assuresign.com>, Microsoft <https://microsoft.com>, John Reilly <https://github.com/johnnyreilly>, Benoit Benezech <https://github.com/bbenezech>, Patricio Zavolinsky <https://github.com/pzavolinsky>, Digiguru <https://github.com/digiguru>, Eric Anderson <https://github.com/ericanderson>, Tanguy Krotoff <https://github.com/tkrotoff>, Dovydas Navickas <https://github.com/DovydasNavickas>, Stéphane Goetz <https://github.com/onigoetz>, Josh Rutherford <https://github.com/theruther4d>, Guilherme Hübner <https://github.com/guilhermehubner>, Ferdy Budhidharma <https://github.com/ferdaber>, Johann Rakotoharisoa <https://github.com/jrakotoharisoa>, Olivier Pascal <https://github.com/pascaloliv>, Martin Hochel <https://github.com/hotell>, Frank Li <https://github.com/franklixuefei>, Jessica Franco <https://github.com/Jessidhia>, Paul Sherman <https://github.com/pshrmn>, Sunil Pai <https://github.com/threepointone>.
react/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- // Type definitions for React 16.7
1
+ // Type definitions for React 16.8
2
2
  // Project: http://facebook.github.io/react/
3
3
  // Definitions by: Asana <https://asana.com>
4
4
  // AssureSign <http://www.assuresign.com>
@@ -18,8 +18,9 @@
18
18
  // Olivier Pascal <https://github.com/pascaloliv>
19
19
  // Martin Hochel <https://github.com/hotell>
20
20
  // Frank Li <https://github.com/franklixuefei>
21
- // Jessica Franco <https://github.com/Kovensky>
21
+ // Jessica Franco <https://github.com/Jessidhia>
22
22
  // Paul Sherman <https://github.com/pshrmn>
23
+ // Sunil Pai <https://github.com/threepointone>
23
24
  // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
24
25
  // TypeScript Version: 2.8
25
26
 
@@ -57,6 +58,10 @@ declare namespace React {
57
58
  ComponentType<P>;
58
59
  type ComponentType<P = {}> = ComponentClass<P> | FunctionComponent<P>;
59
60
 
61
+ type JSXElementConstructor<P> =
62
+ | ((props: P) => ReactElement<any> | null)
63
+ | (new (props: P) => Component<P, any>);
64
+
60
65
  type Key = string | number;
61
66
 
62
67
  interface RefObject<T> {
@@ -78,33 +83,35 @@ declare namespace React {
78
83
  ref?: LegacyRef<T>;
79
84
  }
80
85
 
81
- interface ReactElement<P> {
82
- type: string | ComponentClass<P> | FunctionComponent<P>;
86
+ interface ReactElement<P, T extends string | JSXElementConstructor<any> = string | JSXElementConstructor<any>> {
87
+ type: T;
83
88
  props: P;
84
89
  key: Key | null;
85
90
  }
86
91
 
92
+ interface ReactComponentElement<
93
+ T extends keyof JSX.IntrinsicElements | JSXElementConstructor<any>,
94
+ P = Pick<ComponentProps<T>, Exclude<keyof ComponentProps<T>, 'key' | 'ref'>>
95
+ > extends ReactElement<P, T> { }
96
+
87
97
  /**
88
98
  * @deprecated Please use `FunctionComponentElement`
89
99
  */
90
100
  type SFCElement<P> = FunctionComponentElement<P>;
91
101
 
92
- interface FunctionComponentElement<P> extends ReactElement<P> {
93
- type: FunctionComponent<P>;
102
+ interface FunctionComponentElement<P> extends ReactElement<P, FunctionComponent<P>> {
94
103
  ref?: 'ref' extends keyof P ? P extends { ref?: infer R } ? R : never : never;
95
104
  }
96
105
 
97
106
  type CElement<P, T extends Component<P, ComponentState>> = ComponentElement<P, T>;
98
- interface ComponentElement<P, T extends Component<P, ComponentState>> extends ReactElement<P> {
99
- type: ComponentClass<P>;
107
+ interface ComponentElement<P, T extends Component<P, ComponentState>> extends ReactElement<P, ComponentClass<P>> {
100
108
  ref?: LegacyRef<T>;
101
109
  }
102
110
 
103
111
  type ClassicElement<P> = CElement<P, ClassicComponent<P, ComponentState>>;
104
112
 
105
113
  // string fallback for custom web-components
106
- interface DOMElement<P extends HTMLAttributes<T> | SVGAttributes<T>, T extends Element> extends ReactElement<P> {
107
- type: string;
114
+ interface DOMElement<P extends HTMLAttributes<T> | SVGAttributes<T>, T extends Element> extends ReactElement<P, string> {
108
115
  ref: LegacyRef<T>;
109
116
  }
110
117
 
@@ -469,7 +476,7 @@ declare namespace React {
469
476
  }
470
477
 
471
478
  interface RefForwardingComponent<T, P = {}> {
472
- (props: P & { children?: ReactNode }, ref: Ref<T> | null): ReactElement<any> | null;
479
+ (props: P & { children?: ReactNode }, ref: Ref<T>): ReactElement<any> | null;
473
480
  propTypes?: WeakValidationMap<P>;
474
481
  contextTypes?: ValidationMap<any>;
475
482
  defaultProps?: Partial<P>;
@@ -491,10 +498,6 @@ declare namespace React {
491
498
  getDefaultProps?(): P;
492
499
  }
493
500
 
494
- type JSXElementConstructor<P> =
495
- | ((props: P) => ReactElement<any> | null)
496
- | (new (props: P) => Component<P, any>);
497
-
498
501
  /**
499
502
  * We use an intersection type to infer multiple type parameters from
500
503
  * a single argument, which is useful for many top-level API defs.
@@ -772,9 +775,13 @@ declare namespace React {
772
775
  type Dispatch<A> = (value: A) => void;
773
776
  // Unlike redux, the actions _can_ be anything
774
777
  type Reducer<S, A> = (prevState: S, action: A) => S;
778
+ // types used to try and prevent the compiler from reducing S
779
+ // to a supertype common with the second argument to useReducer()
780
+ type ReducerState<R extends Reducer<any, any>> = R extends Reducer<infer S, any> ? S : never;
781
+ type ReducerAction<R extends Reducer<any, any>> = R extends Reducer<any, infer A> ? A : never;
775
782
  // The identity check is done with the SameValue algorithm (Object.is), which is stricter than ===
776
783
  // TODO (TypeScript 3.0): ReadonlyArray<unknown>
777
- type InputIdentityList = ReadonlyArray<any>;
784
+ type DependencyList = ReadonlyArray<any>;
778
785
 
779
786
  // NOTE: Currently, in alpha.0, the effect callbacks are actually allowed to return anything,
780
787
  // but functions are treated specially. The next version published with hooks will warn if you actually
@@ -791,14 +798,14 @@ declare namespace React {
791
798
  * Accepts a context object (the value returned from `React.createContext`) and returns the current
792
799
  * context value, as given by the nearest context provider for the given context.
793
800
  *
794
- * @version experimental
801
+ * @version 16.8.0
795
802
  * @see https://reactjs.org/docs/hooks-reference.html#usecontext
796
803
  */
797
804
  function useContext<T>(context: Context<T>/*, (not public API) observedBits?: number|boolean */): T;
798
805
  /**
799
806
  * Returns a stateful value, and a function to update it.
800
807
  *
801
- * @version experimental
808
+ * @version 16.8.0
802
809
  * @see https://reactjs.org/docs/hooks-reference.html#usestate
803
810
  */
804
811
  function useState<S>(initialState: S | (() => S)): [S, Dispatch<SetStateAction<S>>];
@@ -809,10 +816,54 @@ declare namespace React {
809
816
  * multiple sub-values. It also lets you optimize performance for components that trigger deep
810
817
  * updates because you can pass `dispatch` down instead of callbacks.
811
818
  *
812
- * @version experimental
819
+ * @version 16.8.0
820
+ * @see https://reactjs.org/docs/hooks-reference.html#usereducer
821
+ */
822
+ // overload where "I" may be a subset of ReducerState<R>; used to provide autocompletion.
823
+ // If "I" matches ReducerState<R> exactly then the last overload will allow initializer to be ommitted.
824
+ // the last overload effectively behaves as if the identity function (x => x) is the initializer.
825
+ function useReducer<R extends Reducer<any, any>, I>(
826
+ reducer: R,
827
+ initializerArg: I & ReducerState<R>,
828
+ initializer: (arg: I & ReducerState<R>) => ReducerState<R>
829
+ ): [ReducerState<R>, Dispatch<ReducerAction<R>>];
830
+ /**
831
+ * An alternative to `useState`.
832
+ *
833
+ * `useReducer` is usually preferable to `useState` when you have complex state logic that involves
834
+ * multiple sub-values. It also lets you optimize performance for components that trigger deep
835
+ * updates because you can pass `dispatch` down instead of callbacks.
836
+ *
837
+ * @version 16.8.0
838
+ * @see https://reactjs.org/docs/hooks-reference.html#usereducer
839
+ */
840
+ // overload for free "I"; all goes as long as initializer converts it into "ReducerState<R>".
841
+ function useReducer<R extends Reducer<any, any>, I>(
842
+ reducer: R,
843
+ initializerArg: I,
844
+ initializer: (arg: I) => ReducerState<R>
845
+ ): [ReducerState<R>, Dispatch<ReducerAction<R>>];
846
+ /**
847
+ * An alternative to `useState`.
848
+ *
849
+ * `useReducer` is usually preferable to `useState` when you have complex state logic that involves
850
+ * multiple sub-values. It also lets you optimize performance for components that trigger deep
851
+ * updates because you can pass `dispatch` down instead of callbacks.
852
+ *
853
+ * @version 16.8.0
813
854
  * @see https://reactjs.org/docs/hooks-reference.html#usereducer
814
855
  */
815
- function useReducer<S, A>(reducer: Reducer<S, A>, initialState: S, initialAction?: A | null): [S, Dispatch<A>];
856
+ // 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
+ // 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
860
+ // supertype between the reducer's return type and the initialState (or the initializer's return type),
861
+ // which would prevent autocompletion from ever working.
862
+ function useReducer<R extends Reducer<any, any>>(
863
+ reducer: R,
864
+ initialState: ReducerState<R>,
865
+ initializer?: undefined
866
+ ): [ReducerState<R>, Dispatch<ReducerAction<R>>];
816
867
  /**
817
868
  * `useRef` returns a mutable ref object whose `.current` property is initialized to the passed argument
818
869
  * (`initialValue`). The returned object will persist for the full lifetime of the component.
@@ -820,7 +871,7 @@ declare namespace React {
820
871
  * Note that `useRef()` is useful for more than the `ref` attribute. It’s handy for keeping any mutable
821
872
  * value around similar to how you’d use instance fields in classes.
822
873
  *
823
- * @version experimental
874
+ * @version 16.8.0
824
875
  * @see https://reactjs.org/docs/hooks-reference.html#useref
825
876
  */
826
877
  // TODO (TypeScript 3.0): <T extends unknown>
@@ -836,7 +887,7 @@ declare namespace React {
836
887
  * Usage note: if you need the result of useRef to be directly mutable, include `| null` in the type
837
888
  * of the generic argument.
838
889
  *
839
- * @version experimental
890
+ * @version 16.8.0
840
891
  * @see https://reactjs.org/docs/hooks-reference.html#useref
841
892
  */
842
893
  // TODO (TypeScript 3.0): <T extends unknown>
@@ -851,44 +902,44 @@ declare namespace React {
851
902
  * If you’re migrating code from a class component, `useLayoutEffect` fires in the same phase as
852
903
  * `componentDidMount` and `componentDidUpdate`.
853
904
  *
854
- * @version experimental
905
+ * @version 16.8.0
855
906
  * @see https://reactjs.org/docs/hooks-reference.html#uselayouteffect
856
907
  */
857
- function useLayoutEffect(effect: EffectCallback, inputs?: InputIdentityList): void;
908
+ function useLayoutEffect(effect: EffectCallback, deps?: DependencyList): void;
858
909
  /**
859
910
  * Accepts a function that contains imperative, possibly effectful code.
860
911
  *
861
912
  * @param effect Imperative function that can return a cleanup function
862
- * @param inputs If present, effect will only activate if the values in the list change.
913
+ * @param deps If present, effect will only activate if the values in the list change.
863
914
  *
864
- * @version experimental
915
+ * @version 16.8.0
865
916
  * @see https://reactjs.org/docs/hooks-reference.html#useeffect
866
917
  */
867
- function useEffect(effect: EffectCallback, inputs?: InputIdentityList): void;
918
+ function useEffect(effect: EffectCallback, deps?: DependencyList): void;
868
919
  // NOTE: this does not accept strings, but this will have to be fixed by removing strings from type Ref<T>
869
920
  /**
870
- * `useImperativeMethods` customizes the instance value that is exposed to parent components when using
921
+ * `useImperativeHandle` customizes the instance value that is exposed to parent components when using
871
922
  * `ref`. As always, imperative code using refs should be avoided in most cases.
872
923
  *
873
- * `useImperativeMethods` should be used with `React.forwardRef`.
924
+ * `useImperativeHandle` should be used with `React.forwardRef`.
874
925
  *
875
- * @version experimental
876
- * @see https://reactjs.org/docs/hooks-reference.html#useimperativemethods
926
+ * @version 16.8.0
927
+ * @see https://reactjs.org/docs/hooks-reference.html#useimperativehandle
877
928
  */
878
- function useImperativeMethods<T, R extends T>(ref: Ref<T>|undefined, init: () => R, inputs?: InputIdentityList): void;
929
+ function useImperativeHandle<T, R extends T>(ref: Ref<T>|undefined, init: () => R, deps?: DependencyList): void;
879
930
  // I made 'inputs' required here and in useMemo as there's no point to memoizing without the memoization key
880
931
  // useCallback(X) is identical to just using X, useMemo(() => Y) is identical to just using Y.
881
932
  /**
882
933
  * `useCallback` will return a memoized version of the callback that only changes if one of the `inputs`
883
934
  * has changed.
884
935
  *
885
- * @version experimental
936
+ * @version 16.8.0
886
937
  * @see https://reactjs.org/docs/hooks-reference.html#usecallback
887
938
  */
888
939
  // TODO (TypeScript 3.0): <T extends (...args: never[]) => unknown>
889
- function useCallback<T extends (...args: any[]) => any>(callback: T, inputs: InputIdentityList): T;
940
+ function useCallback<T extends (...args: any[]) => any>(callback: T, deps: DependencyList): T;
890
941
  /**
891
- * `useMemo` will only recompute the memoized value when one of the `inputs` has changed.
942
+ * `useMemo` will only recompute the memoized value when one of the `deps` has changed.
892
943
  *
893
944
  * Usage note: if calling `useMemo` with a referentially stable function, also give it as the input in
894
945
  * the second argument.
@@ -902,10 +953,22 @@ declare namespace React {
902
953
  * }
903
954
  * ```
904
955
  *
905
- * @version experimental
956
+ * @version 16.8.0
906
957
  * @see https://reactjs.org/docs/hooks-reference.html#usememo
907
958
  */
908
- function useMemo<T>(factory: () => T, inputs: InputIdentityList): T;
959
+ function useMemo<T>(factory: () => T, deps: DependencyList): T;
960
+ /**
961
+ * `useDebugValue` can be used to display a label for custom hooks in React DevTools.
962
+ *
963
+ * NOTE: We don’t recommend adding debug values to every custom hook.
964
+ * It’s most valuable for custom hooks that are part of shared libraries.
965
+ *
966
+ * @version 16.8.0
967
+ * @see https://reactjs.org/docs/hooks-reference.html#usedebugvalue
968
+ */
969
+ // the name of the custom hook is itself derived from the function name at runtime:
970
+ // it's just the function name without the "use" prefix.
971
+ function useDebugValue<T>(value: T, format?: (value: T) => any): void;
909
972
 
910
973
  //
911
974
  // Event System
@@ -2586,12 +2649,11 @@ declare namespace React {
2586
2649
  // ----------------------------------------------------------------------
2587
2650
 
2588
2651
  interface ReactChildren {
2589
- map<T, C extends ReactElement<any>>(children: C[], fn: (child: C, index: number) => T): T[];
2590
- map<T>(children: ReactNode, fn: (child: ReactChild, index: number) => T): T[];
2591
- forEach(children: ReactNode, fn: (child: ReactChild, index: number) => void): void;
2592
- count(children: ReactNode): number;
2593
- only(children: ReactNode): ReactElement<any>;
2594
- toArray(children: ReactNode): ReactChild[];
2652
+ map<T, C>(children: C | C[], fn: (child: C, index: number) => T): T[];
2653
+ forEach<C>(children: C | C[], fn: (child: C, index: number) => void): void;
2654
+ count(children: any): number;
2655
+ only<C>(children: C): C extends any[] ? never : C;
2656
+ toArray<C>(children: C | C[]): C[];
2595
2657
  }
2596
2658
 
2597
2659
  //
@@ -2670,7 +2732,7 @@ type ReactManagedAttributes<C, P> = C extends { propTypes: infer T; defaultProps
2670
2732
  declare global {
2671
2733
  namespace JSX {
2672
2734
  // tslint:disable-next-line:no-empty-interface
2673
- interface Element extends React.ReactElement<any> { }
2735
+ interface Element extends React.ReactElement<any, any> { }
2674
2736
  interface ElementClass extends React.Component<any> {
2675
2737
  render(): React.ReactNode;
2676
2738
  }
react/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@types/react",
3
- "version": "16.7.20",
3
+ "version": "16.8.1",
4
4
  "description": "TypeScript definitions for React",
5
5
  "license": "MIT",
6
6
  "contributors": [
@@ -93,13 +93,18 @@
93
93
  },
94
94
  {
95
95
  "name": "Jessica Franco",
96
- "url": "https://github.com/Kovensky",
97
- "githubUsername": "Kovensky"
96
+ "url": "https://github.com/Jessidhia",
97
+ "githubUsername": "Jessidhia"
98
98
  },
99
99
  {
100
100
  "name": "Paul Sherman",
101
101
  "url": "https://github.com/pshrmn",
102
102
  "githubUsername": "pshrmn"
103
+ },
104
+ {
105
+ "name": "Sunil Pai",
106
+ "url": "https://github.com/threepointone",
107
+ "githubUsername": "threepointone"
103
108
  }
104
109
  ],
105
110
  "main": "",
@@ -113,6 +118,6 @@
113
118
  "@types/prop-types": "*",
114
119
  "csstype": "^2.2.0"
115
120
  },
116
- "typesPublisherContentHash": "2a1011b01a2d9f4b782236b72ecd78ba59aab59fb1090764938aa629b82db26f",
121
+ "typesPublisherContentHash": "5e6c26eca19df3467cf389dc97a7d83025def98e1e1d0472fc639ca41afa8ac0",
117
122
  "typeScriptVersion": "2.8"
118
123
  }