@types/react 16.8.0 → 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.
- react/README.md +1 -1
- react/index.d.ts +79 -19
- react/package.json +2 -2
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:
|
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
|
|
react/index.d.ts
CHANGED
@@ -775,9 +775,13 @@ declare namespace React {
|
|
775
775
|
type Dispatch<A> = (value: A) => void;
|
776
776
|
// Unlike redux, the actions _can_ be anything
|
777
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;
|
778
782
|
// The identity check is done with the SameValue algorithm (Object.is), which is stricter than ===
|
779
783
|
// TODO (TypeScript 3.0): ReadonlyArray<unknown>
|
780
|
-
type
|
784
|
+
type DependencyList = ReadonlyArray<any>;
|
781
785
|
|
782
786
|
// NOTE: Currently, in alpha.0, the effect callbacks are actually allowed to return anything,
|
783
787
|
// but functions are treated specially. The next version published with hooks will warn if you actually
|
@@ -794,14 +798,14 @@ declare namespace React {
|
|
794
798
|
* Accepts a context object (the value returned from `React.createContext`) and returns the current
|
795
799
|
* context value, as given by the nearest context provider for the given context.
|
796
800
|
*
|
797
|
-
* @version
|
801
|
+
* @version 16.8.0
|
798
802
|
* @see https://reactjs.org/docs/hooks-reference.html#usecontext
|
799
803
|
*/
|
800
804
|
function useContext<T>(context: Context<T>/*, (not public API) observedBits?: number|boolean */): T;
|
801
805
|
/**
|
802
806
|
* Returns a stateful value, and a function to update it.
|
803
807
|
*
|
804
|
-
* @version
|
808
|
+
* @version 16.8.0
|
805
809
|
* @see https://reactjs.org/docs/hooks-reference.html#usestate
|
806
810
|
*/
|
807
811
|
function useState<S>(initialState: S | (() => S)): [S, Dispatch<SetStateAction<S>>];
|
@@ -812,10 +816,54 @@ declare namespace React {
|
|
812
816
|
* multiple sub-values. It also lets you optimize performance for components that trigger deep
|
813
817
|
* updates because you can pass `dispatch` down instead of callbacks.
|
814
818
|
*
|
815
|
-
* @version
|
819
|
+
* @version 16.8.0
|
816
820
|
* @see https://reactjs.org/docs/hooks-reference.html#usereducer
|
817
821
|
*/
|
818
|
-
|
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
|
854
|
+
* @see https://reactjs.org/docs/hooks-reference.html#usereducer
|
855
|
+
*/
|
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>>];
|
819
867
|
/**
|
820
868
|
* `useRef` returns a mutable ref object whose `.current` property is initialized to the passed argument
|
821
869
|
* (`initialValue`). The returned object will persist for the full lifetime of the component.
|
@@ -823,7 +871,7 @@ declare namespace React {
|
|
823
871
|
* Note that `useRef()` is useful for more than the `ref` attribute. It’s handy for keeping any mutable
|
824
872
|
* value around similar to how you’d use instance fields in classes.
|
825
873
|
*
|
826
|
-
* @version
|
874
|
+
* @version 16.8.0
|
827
875
|
* @see https://reactjs.org/docs/hooks-reference.html#useref
|
828
876
|
*/
|
829
877
|
// TODO (TypeScript 3.0): <T extends unknown>
|
@@ -839,7 +887,7 @@ declare namespace React {
|
|
839
887
|
* Usage note: if you need the result of useRef to be directly mutable, include `| null` in the type
|
840
888
|
* of the generic argument.
|
841
889
|
*
|
842
|
-
* @version
|
890
|
+
* @version 16.8.0
|
843
891
|
* @see https://reactjs.org/docs/hooks-reference.html#useref
|
844
892
|
*/
|
845
893
|
// TODO (TypeScript 3.0): <T extends unknown>
|
@@ -854,20 +902,20 @@ declare namespace React {
|
|
854
902
|
* If you’re migrating code from a class component, `useLayoutEffect` fires in the same phase as
|
855
903
|
* `componentDidMount` and `componentDidUpdate`.
|
856
904
|
*
|
857
|
-
* @version
|
905
|
+
* @version 16.8.0
|
858
906
|
* @see https://reactjs.org/docs/hooks-reference.html#uselayouteffect
|
859
907
|
*/
|
860
|
-
function useLayoutEffect(effect: EffectCallback,
|
908
|
+
function useLayoutEffect(effect: EffectCallback, deps?: DependencyList): void;
|
861
909
|
/**
|
862
910
|
* Accepts a function that contains imperative, possibly effectful code.
|
863
911
|
*
|
864
912
|
* @param effect Imperative function that can return a cleanup function
|
865
|
-
* @param
|
913
|
+
* @param deps If present, effect will only activate if the values in the list change.
|
866
914
|
*
|
867
|
-
* @version
|
915
|
+
* @version 16.8.0
|
868
916
|
* @see https://reactjs.org/docs/hooks-reference.html#useeffect
|
869
917
|
*/
|
870
|
-
function useEffect(effect: EffectCallback,
|
918
|
+
function useEffect(effect: EffectCallback, deps?: DependencyList): void;
|
871
919
|
// NOTE: this does not accept strings, but this will have to be fixed by removing strings from type Ref<T>
|
872
920
|
/**
|
873
921
|
* `useImperativeHandle` customizes the instance value that is exposed to parent components when using
|
@@ -875,23 +923,23 @@ declare namespace React {
|
|
875
923
|
*
|
876
924
|
* `useImperativeHandle` should be used with `React.forwardRef`.
|
877
925
|
*
|
878
|
-
* @version
|
926
|
+
* @version 16.8.0
|
879
927
|
* @see https://reactjs.org/docs/hooks-reference.html#useimperativehandle
|
880
928
|
*/
|
881
|
-
function useImperativeHandle<T, R extends T>(ref: Ref<T>|undefined, init: () => R,
|
929
|
+
function useImperativeHandle<T, R extends T>(ref: Ref<T>|undefined, init: () => R, deps?: DependencyList): void;
|
882
930
|
// I made 'inputs' required here and in useMemo as there's no point to memoizing without the memoization key
|
883
931
|
// useCallback(X) is identical to just using X, useMemo(() => Y) is identical to just using Y.
|
884
932
|
/**
|
885
933
|
* `useCallback` will return a memoized version of the callback that only changes if one of the `inputs`
|
886
934
|
* has changed.
|
887
935
|
*
|
888
|
-
* @version
|
936
|
+
* @version 16.8.0
|
889
937
|
* @see https://reactjs.org/docs/hooks-reference.html#usecallback
|
890
938
|
*/
|
891
939
|
// TODO (TypeScript 3.0): <T extends (...args: never[]) => unknown>
|
892
|
-
function useCallback<T extends (...args: any[]) => any>(callback: T,
|
940
|
+
function useCallback<T extends (...args: any[]) => any>(callback: T, deps: DependencyList): T;
|
893
941
|
/**
|
894
|
-
* `useMemo` will only recompute the memoized value when one of the `
|
942
|
+
* `useMemo` will only recompute the memoized value when one of the `deps` has changed.
|
895
943
|
*
|
896
944
|
* Usage note: if calling `useMemo` with a referentially stable function, also give it as the input in
|
897
945
|
* the second argument.
|
@@ -905,10 +953,22 @@ declare namespace React {
|
|
905
953
|
* }
|
906
954
|
* ```
|
907
955
|
*
|
908
|
-
* @version
|
956
|
+
* @version 16.8.0
|
909
957
|
* @see https://reactjs.org/docs/hooks-reference.html#usememo
|
910
958
|
*/
|
911
|
-
function useMemo<T>(factory: () => 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;
|
912
972
|
|
913
973
|
//
|
914
974
|
// Event System
|
react/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@types/react",
|
3
|
-
"version": "16.8.
|
3
|
+
"version": "16.8.1",
|
4
4
|
"description": "TypeScript definitions for React",
|
5
5
|
"license": "MIT",
|
6
6
|
"contributors": [
|
@@ -118,6 +118,6 @@
|
|
118
118
|
"@types/prop-types": "*",
|
119
119
|
"csstype": "^2.2.0"
|
120
120
|
},
|
121
|
-
"typesPublisherContentHash": "
|
121
|
+
"typesPublisherContentHash": "5e6c26eca19df3467cf389dc97a7d83025def98e1e1d0472fc639ca41afa8ac0",
|
122
122
|
"typeScriptVersion": "2.8"
|
123
123
|
}
|