Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions packages/react-native/__typetests__/globals.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,27 @@ function testRequestAnimationFrame(){
);
}

function testRequestIdleCallback() {
cancelIdleCallback(null);
cancelIdleCallback(undefined);

let handle = requestIdleCallback(deadline => {
const didTimeout: boolean = deadline.didTimeout;
const remaining: number = deadline.timeRemaining();
console.log(didTimeout, remaining);
});
cancelIdleCallback(handle);

handle = requestIdleCallback(noop, { timeout: 100 });
cancelIdleCallback(handle);

// @ts-expect-error
requestIdleCallback(noop, { timeout: 'wrong-type' });

// @ts-expect-error
cancelIdleCallback('wrong-type');
}

const fetchCopy: WindowOrWorkerGlobalScope['fetch'] = fetch;

const myHeaders = new Headers();
Expand Down
9 changes: 9 additions & 0 deletions packages/react-native/src/types/globals.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,15 @@ declare global {
function cancelAnimationFrame(handle: number | null | undefined): void;
function requestAnimationFrame(callback: (time: number) => void): number;

function requestIdleCallback(
callback: (deadline: {
didTimeout: boolean;
timeRemaining: () => number;
}) => void,
options?: {timeout: number},
): number;
function cancelIdleCallback(handle: number | null | undefined): void;

function fetchBundle(
bundleId: number,
callback: (error?: Error | null) => void,
Expand Down