Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
19 changes: 19 additions & 0 deletions packages/react-native/__typetests__/globals.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,25 @@ function testRequestAnimationFrame(){
);
}

function testRequestIdleCallback() {
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' });

// handle is opaque: object on New Architecture, number on legacy
// @ts-expect-error
const handleIsNotNumber: number = requestIdleCallback(noop);
}

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

const myHeaders = new Headers();
Expand Down
10 changes: 10 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,16 @@ declare global {
function cancelAnimationFrame(handle: number | null | undefined): void;
function requestAnimationFrame(callback: (time: number) => void): number;

type IdleCallbackID = unknown;
Comment thread
Critteros marked this conversation as resolved.
Outdated
function requestIdleCallback(
callback: (deadline: {
didTimeout: boolean;
timeRemaining: () => number;
}) => void,
options?: {timeout: number},
): IdleCallbackID;
function cancelIdleCallback(handle: IdleCallbackID): void;

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