File tree 2 files changed +43
-0
lines changed
2 files changed +43
-0
lines changed Original file line number Diff line number Diff line change @@ -102,4 +102,31 @@ declare module '.' {
102
102
* @see https://reactjs.org/docs/concurrent-mode-patterns.html#suspenselist
103
103
*/
104
104
export const SuspenseList : ExoticComponent < SuspenseListProps > ;
105
+
106
+ interface ThenableImpl < T > {
107
+ then ( onFulfill : ( value : T ) => unknown , onReject : ( error : unknown ) => unknown ) : void | PromiseLike < unknown > ;
108
+ }
109
+ interface UntrackedThenable < T > extends ThenableImpl < T > {
110
+ status ?: void ;
111
+ }
112
+
113
+ export interface PendingThenable < T > extends ThenableImpl < T > {
114
+ status : 'pending' ;
115
+ }
116
+
117
+ export interface FulfilledThenable < T > extends ThenableImpl < T > {
118
+ status : 'fulfilled' ;
119
+ value : T ;
120
+ }
121
+
122
+ export interface RejectedThenable < T > extends ThenableImpl < T > {
123
+ status : 'rejected' ;
124
+ reason : unknown ;
125
+ }
126
+
127
+ export type Thenable < T > = UntrackedThenable < T > | PendingThenable < T > | FulfilledThenable < T > | RejectedThenable < T > ;
128
+
129
+ export type Usable < T > = Thenable < T > | Context < T > ;
130
+
131
+ export function experimental_use < T > ( usable : Usable < T > ) : T ;
105
132
}
Original file line number Diff line number Diff line change @@ -36,3 +36,19 @@ function suspenseTest() {
36
36
< React . Suspense fallback = "Loading" > A</ React . Suspense >
37
37
< React . Suspense fallback = "Loading" > B</ React . Suspense >
38
38
</ React . SuspenseList > ;
39
+
40
+ const contextUsers = React . createContext ( [ 'HAL' ] ) ;
41
+ const promisedUsers = Promise . resolve ( [ 'Dave' ] ) ;
42
+
43
+ function useUse ( ) {
44
+ // @ts -expect-error Missing value
45
+ React . experimental_use ( ) ;
46
+
47
+ // $ExpectType string[]
48
+ const users = React . experimental_use ( promisedUsers ) ;
49
+ // @ts -expect-error incompatible type. Mainly to potentially inspect TypeScript error message
50
+ React . experimental_use ( { } ) ;
51
+
52
+ // $ExpectType string[]
53
+ const contextValue = React . experimental_use ( contextUsers ) ;
54
+ }
You can’t perform that action at this time.
0 commit comments