@@ -34,12 +34,14 @@ function MyApp() {
34
34
< UserProvider >
35
35
< Text > Foo!</ Text >
36
36
< Addition />
37
+ < AdditionWithTypes />
37
38
</ UserProvider >
38
39
</ View >
39
40
) : null ;
40
41
}
41
42
42
43
let higherScopedSum : number ;
44
+ let typedHigherScopedSum : number ;
43
45
// :remove-end:
44
46
45
47
function Addition ( ) {
@@ -68,6 +70,27 @@ function Addition() {
68
70
// :remove-end:
69
71
}
70
72
// :snippet-end:
73
+ // :snippet-start: addition-with-types
74
+ type FunctionTypes = {
75
+ sum : ( a : number , b : number ) => number ;
76
+ } & Realm . DefaultFunctionsFactory ;
77
+
78
+ function AdditionWithTypes ( ) {
79
+ const user = useUser < FunctionTypes , SimpleObject , Realm . DefaultUserProfileData > ( ) ;
80
+ async function addNumbers ( numA : number , numB : number ) {
81
+ const sum = await user ?. functions . sum ( numA , numB ) ;
82
+ // :remove-start:
83
+ expect ( sum ) . toBe ( 3 ) ;
84
+ typedHigherScopedSum = sum as number ;
85
+ // :remove-end:
86
+ return sum ;
87
+ }
88
+ // ...
89
+ // :remove-start:
90
+ return < Button onPress = { ( ) => addNumbers ( 1 , 2 ) } testID = 'test-typed-function-call' title = 'Test Me!' /> ;
91
+ // :remove-end:
92
+ }
93
+ // :snippet-end:
71
94
72
95
afterEach ( async ( ) => await App . getApp ( APP_ID ) . currentUser ?. logOut ( ) ) ;
73
96
@@ -78,3 +101,10 @@ test('Call Atlas Function', async () => {
78
101
fireEvent . press ( button ) ;
79
102
await waitFor ( ( ) => expect ( higherScopedSum ) . toBe ( 3 ) ) ;
80
103
} ) ;
104
+ test ( 'Call Typed Atlas Function' , async ( ) => {
105
+ const { getByTestId} = render ( < AppWrapper /> ) ;
106
+
107
+ const button = await waitFor ( ( ) => getByTestId ( 'test-typed-function-call' ) ) ;
108
+ fireEvent . press ( button ) ;
109
+ await waitFor ( ( ) => expect ( higherScopedSum ) . toBe ( 3 ) ) ;
110
+ } ) ;
0 commit comments