Commit c086431
Add TypeScript declarations for requestIdleCallback and cancelIdleCallback (#57545)
Summary:
`requestIdleCallback` and `cancelIdleCallback` exist at runtime on both architectures. The New Architecture has a native implementation since 0.75 in #44759 (landed as abfadc6, closing #44636). Legacy architecture has a JS-timer-based implementation in `JSTimers` since 2016 (18394fb, follow-up to #5052). Support for the `options` param was added in cf51aee. The API is documented at https://reactnative.dev/docs/global-requestIdleCallback
Flow libdefs already declare both functions in`flow/global.js`
The public TypeScript declarations never included them.
React Native projects compile without `lib: ["dom"]`, so TypeScript users get no declaration
This PR adds the declarations to the `Timer Functions` region of `src/types/globals.d.ts`, based on the Flow signatures
## Changelog:
[GENERAL] [ADDED] - Add TypeScript declarations for `requestIdleCallback` and `cancelIdleCallback`
Pull Request resolved: #57545
Test Plan:
Added `testRequestIdleCallback()` to `packages/react-native/__typetests__/globals.tsx`
```
yarn test-generated-typescript
yarn test-typescript-legacy
yarn lint
yarn prettier
```
Reviewed By: javache
Differential Revision: D112540741
Pulled By: fabriziocucci
fbshipit-source-id: 77f26b4729ecd6cd6b723da026d45730cee229951 parent 7825d51 commit c086431
2 files changed
Lines changed: 33 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
137 | 137 | | |
138 | 138 | | |
139 | 139 | | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
140 | 164 | | |
141 | 165 | | |
142 | 166 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
125 | 125 | | |
126 | 126 | | |
127 | 127 | | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
128 | 137 | | |
129 | 138 | | |
130 | 139 | | |
| |||
0 commit comments