Skip to content

Commit

Permalink
[flow][libdef] Mark React.Ref as clearly deprecated
Browse files Browse the repository at this point in the history
Summary:
Use the deprecated jsdoc to clearly indicate that it's deprecated, and it will at least show as crossed-over during autocomplete.

Changelog: [libdef] `React.Ref` is marked as deprecated. Use `React.RefSetter` instead for ref props, and `React.RefObject` for returns of `useRef`

Reviewed By: gkz

Differential Revision: D62585112

fbshipit-source-id: 880e14f31535856b23a3f4c21210daf1be991139
  • Loading branch information
SamChou19815 authored and facebook-github-bot committed Sep 12, 2024
1 parent af733af commit cc4b100
Show file tree
Hide file tree
Showing 17 changed files with 337 additions and 329 deletions.
10 changes: 9 additions & 1 deletion lib/react.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ declare type React$Key = string | number;
declare opaque type React$RefObject<T>: {| current: T |}

/**
* DEPRECATED: The type of the ref prop available on all React components,
* @deprecated The type of the ref prop available on all React components,
* including legacy number | string refs.
*/
declare type React$Ref<ElementType: React$ElementType> =
Expand Down Expand Up @@ -235,6 +235,10 @@ declare namespace React {
type ElementType = React$ElementType;

type Key = React$Key;
/**
* @deprecated The type of the ref prop available on all React components,
* including legacy number | string refs.
*/
type Ref<C> = React$Ref<C>;
type RefSetter<-T> = React$RefSetter<T>;
type Node = React$Node;
Expand Down Expand Up @@ -1028,6 +1032,10 @@ declare module react {
type ElementType = React$ElementType;

type Key = React$Key;
/**
* @deprecated The type of the ref prop available on all React components,
* including legacy number | string refs.
*/
type Ref<C> = React$Ref<C>;
type RefSetter<-T> = React$RefSetter<T>;
type Node = React$Node;
Expand Down
4 changes: 2 additions & 2 deletions tests/badly_positioned_react/badly_positioned_react.exp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ References:
test.js:21:29
21| const Foo1 = create(create1<{||}>(Foo));
^^^^ [2]
<BUILTINS>/react.js:354:38
354| declare export type ComponentType<-P> = React$ComponentType<P>;
<BUILTINS>/react.js:358:38
358| declare export type ComponentType<-P> = React$ComponentType<P>;
^ [3]


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ Cannot cast `3` to `React.FragmentType` because number [1] is incompatible with
^ [1]

References:
<BUILTINS>/react.js:751:5
<BUILTINS>/react.js:755:5
v------------------------------------------------------
751| declare component Fragment<Renders: React$Node = void>(
752| children?: Renders,
753| ) renders Renders;
755| declare component Fragment<Renders: React$Node = void>(
756| children?: Renders,
757| ) renders Renders;
-----------------^ [2]


Expand Down
4 changes: 2 additions & 2 deletions tests/new_generics/new_generics.exp
Original file line number Diff line number Diff line change
Expand Up @@ -1105,8 +1105,8 @@ References:
react.js:13:28
13| a as React.ComponentType<{a: number}>; // nope, contravariance
^^^^^^^^^^^ [2]
<BUILTINS>/react.js:354:38
354| declare export type ComponentType<-P> = React$ComponentType<P>;
<BUILTINS>/react.js:358:38
358| declare export type ComponentType<-P> = React$ComponentType<P>;
^ [3]


Expand Down
52 changes: 26 additions & 26 deletions tests/new_merge_unsupported/new_merge_unsupported.exp
Original file line number Diff line number Diff line change
Expand Up @@ -525,8 +525,8 @@ annotation for class extends [2]. [invalid-exported-annotation]
^^^^^^^^^^^^^ [2]

References:
<BUILTINS>/react.js:399:53
399| declare export type Config<Props, DefaultProps> = React$Config<Props, DefaultProps>;
<BUILTINS>/react.js:403:53
403| declare export type Config<Props, DefaultProps> = React$Config<Props, DefaultProps>;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [1]


Expand Down Expand Up @@ -554,8 +554,8 @@ annotation for property `f` [2]. [invalid-exported-annotation]
^^^ [2]

References:
<BUILTINS>/react.js:399:53
399| declare export type Config<Props, DefaultProps> = React$Config<Props, DefaultProps>;
<BUILTINS>/react.js:403:53
403| declare export type Config<Props, DefaultProps> = React$Config<Props, DefaultProps>;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [1]


Expand All @@ -569,8 +569,8 @@ annotation for computed property [2]. [invalid-exported-annotation]
^^^^^^^^^^^^^^^ [2]

References:
<BUILTINS>/react.js:399:53
399| declare export type Config<Props, DefaultProps> = React$Config<Props, DefaultProps>;
<BUILTINS>/react.js:403:53
403| declare export type Config<Props, DefaultProps> = React$Config<Props, DefaultProps>;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [1]


Expand All @@ -592,8 +592,8 @@ spread [2]. [invalid-exported-annotation]
^^^^^^^^ [2]

References:
<BUILTINS>/react.js:399:53
399| declare export type Config<Props, DefaultProps> = React$Config<Props, DefaultProps>;
<BUILTINS>/react.js:403:53
403| declare export type Config<Props, DefaultProps> = React$Config<Props, DefaultProps>;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [1]


Expand All @@ -607,8 +607,8 @@ exact [2]. [invalid-exported-annotation]
^^^^^^^^^ [2]

References:
<BUILTINS>/react.js:399:53
399| declare export type Config<Props, DefaultProps> = React$Config<Props, DefaultProps>;
<BUILTINS>/react.js:403:53
403| declare export type Config<Props, DefaultProps> = React$Config<Props, DefaultProps>;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [1]


Expand All @@ -622,8 +622,8 @@ for statics [2]. [invalid-exported-annotation]
^^^^^^^^ [2]

References:
<BUILTINS>/react.js:399:53
399| declare export type Config<Props, DefaultProps> = React$Config<Props, DefaultProps>;
<BUILTINS>/react.js:403:53
403| declare export type Config<Props, DefaultProps> = React$Config<Props, DefaultProps>;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [1]


Expand Down Expand Up @@ -665,8 +665,8 @@ annotation for property `f` [2]. [invalid-exported-annotation]
^^^^ [2]

References:
<BUILTINS>/react.js:399:53
399| declare export type Config<Props, DefaultProps> = React$Config<Props, DefaultProps>;
<BUILTINS>/react.js:403:53
403| declare export type Config<Props, DefaultProps> = React$Config<Props, DefaultProps>;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [1]


Expand All @@ -680,8 +680,8 @@ for prototype [2]. [invalid-exported-annotation]
^ [2]

References:
<BUILTINS>/react.js:399:53
399| declare export type Config<Props, DefaultProps> = React$Config<Props, DefaultProps>;
<BUILTINS>/react.js:403:53
403| declare export type Config<Props, DefaultProps> = React$Config<Props, DefaultProps>;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [1]


Expand All @@ -695,8 +695,8 @@ mixins [2]. [invalid-exported-annotation]
^ [2]

References:
<BUILTINS>/react.js:399:53
399| declare export type Config<Props, DefaultProps> = React$Config<Props, DefaultProps>;
<BUILTINS>/react.js:403:53
403| declare export type Config<Props, DefaultProps> = React$Config<Props, DefaultProps>;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [1]


Expand Down Expand Up @@ -724,8 +724,8 @@ annotation for unary minus [2]. [invalid-exported-annotation]
^^ [2]

References:
<BUILTINS>/react.js:399:53
399| declare export type Config<Props, DefaultProps> = React$Config<Props, DefaultProps>;
<BUILTINS>/react.js:403:53
403| declare export type Config<Props, DefaultProps> = React$Config<Props, DefaultProps>;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [1]


Expand Down Expand Up @@ -753,8 +753,8 @@ for unary not [2]. [invalid-exported-annotation]
^^ [2]

References:
<BUILTINS>/react.js:399:53
399| declare export type Config<Props, DefaultProps> = React$Config<Props, DefaultProps>;
<BUILTINS>/react.js:403:53
403| declare export type Config<Props, DefaultProps> = React$Config<Props, DefaultProps>;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [1]


Expand All @@ -768,8 +768,8 @@ annotation for `$KeyMirror` [2]. [invalid-exported-annotation]
^^^^^^^^^^^^^ [2]

References:
<BUILTINS>/react.js:399:53
399| declare export type Config<Props, DefaultProps> = React$Config<Props, DefaultProps>;
<BUILTINS>/react.js:403:53
403| declare export type Config<Props, DefaultProps> = React$Config<Props, DefaultProps>;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [1]


Expand All @@ -783,8 +783,8 @@ for key set [2]. [invalid-exported-annotation]
^^^^^^^^ [2]

References:
<BUILTINS>/react.js:399:53
399| declare export type Config<Props, DefaultProps> = React$Config<Props, DefaultProps>;
<BUILTINS>/react.js:403:53
403| declare export type Config<Props, DefaultProps> = React$Config<Props, DefaultProps>;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [1]


Expand Down
Loading

0 comments on commit cc4b100

Please sign in to comment.