Define Flow types for Performance APIs (#53433)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/53433

Changelog: [internal]

This adds the definitions for the Web Performance APIs in the global scope.

Reviewed By: zeyap

Differential Revision: D80811659

fbshipit-source-id: a81117a27a480ba03f8feb2e813a3a66a10307f9
This commit is contained in:
Rubén Norte
2025-09-08 14:56:46 +01:00
committed by Vitali Zaidman
parent cdfe1ecd52
commit ac2fe26cf2
+157
View File
@@ -88,12 +88,169 @@ declare var navigator: Navigator;
// https://developer.mozilla.org/en-US/docs/Web/API/DOMHighResTimeStamp
declare type DOMHighResTimeStamp = number;
type PerformanceEntryFilterOptions = {
entryType: string,
name: string,
...
};
// https://www.w3.org/TR/performance-timeline-2/
declare class PerformanceEntry {
duration: DOMHighResTimeStamp;
entryType: string;
name: string;
startTime: DOMHighResTimeStamp;
toJSON(): string;
}
// https://w3c.github.io/user-timing/#performancemark
declare class PerformanceMark extends PerformanceEntry {
constructor(name: string, markOptions?: PerformanceMarkOptions): void;
+detail: mixed;
}
// https://w3c.github.io/user-timing/#performancemeasure
declare class PerformanceMeasure extends PerformanceEntry {
+detail: mixed;
}
// https://w3c.github.io/server-timing/#the-performanceservertiming-interface
declare class PerformanceServerTiming {
description: string;
duration: DOMHighResTimeStamp;
name: string;
toJSON(): string;
}
// https://www.w3.org/TR/resource-timing-2/#sec-performanceresourcetiming
// https://w3c.github.io/server-timing/#extension-to-the-performanceresourcetiming-interface
declare class PerformanceResourceTiming extends PerformanceEntry {
connectEnd: number;
connectStart: number;
decodedBodySize: number;
domainLookupEnd: number;
domainLookupStart: number;
encodedBodySize: number;
fetchStart: number;
initiatorType: string;
nextHopProtocol: string;
redirectEnd: number;
redirectStart: number;
requestStart: number;
responseEnd: number;
responseStart: number;
secureConnectionStart: number;
serverTiming: Array<PerformanceServerTiming>;
transferSize: number;
workerStart: number;
}
// https://w3c.github.io/event-timing/#sec-performance-event-timing
declare class PerformanceEventTiming extends PerformanceEntry {
cancelable: boolean;
interactionId: number;
processingEnd: number;
processingStart: number;
target: ?Node;
}
// https://w3c.github.io/longtasks/#taskattributiontiming
declare class TaskAttributionTiming extends PerformanceEntry {
containerId: string;
containerName: string;
containerSrc: string;
containerType: string;
}
// https://w3c.github.io/longtasks/#sec-PerformanceLongTaskTiming
declare class PerformanceLongTaskTiming extends PerformanceEntry {
attribution: $ReadOnlyArray<TaskAttributionTiming>;
}
// https://www.w3.org/TR/user-timing/#extensions-performance-interface
declare type PerformanceMarkOptions = {
detail?: mixed,
startTime?: number,
};
declare type PerformanceMeasureOptions = {
detail?: mixed,
duration?: number,
end?: number | string,
start?: number | string,
};
type EventCountsForEachCallbackType =
| (() => void)
| ((value: number) => void)
| ((value: number, key: string) => void)
| ((value: number, key: string, map: Map<string, number>) => void);
// https://www.w3.org/TR/event-timing/#eventcounts
declare interface EventCounts {
entries(): Iterator<[string, number]>;
forEach(callback: EventCountsForEachCallbackType): void;
get(key: string): ?number;
has(key: string): boolean;
keys(): Iterator<string>;
size: number;
values(): Iterator<number>;
}
declare class Performance {
clearMarks(name?: string): void;
clearMeasures(name?: string): void;
eventCounts: EventCounts;
getEntries: (
options?: PerformanceEntryFilterOptions,
) => Array<PerformanceEntry>;
getEntriesByName: (name: string, type?: string) => Array<PerformanceEntry>;
getEntriesByType: (type: string) => Array<PerformanceEntry>;
mark(name: string, options?: PerformanceMarkOptions): PerformanceMark;
measure(
name: string,
startMarkOrOptions?: string | PerformanceMeasureOptions,
endMark?: string,
): PerformanceMeasure;
now: () => DOMHighResTimeStamp;
toJSON(): string;
}
declare var performance: Performance;
type PerformanceEntryList = Array<PerformanceEntry>;
declare interface PerformanceObserverEntryList {
getEntries(): PerformanceEntryList;
getEntriesByName(name: string, type: ?string): PerformanceEntryList;
getEntriesByType(type: string): PerformanceEntryList;
}
type PerformanceObserverInit = {
buffered?: boolean,
entryTypes?: Array<string>,
type?: string,
...
};
declare class PerformanceObserver {
constructor(
callback: (
entries: PerformanceObserverEntryList,
observer: PerformanceObserver,
) => mixed,
): void;
disconnect(): void;
observe(options: ?PerformanceObserverInit): void;
static supportedEntryTypes: Array<string>;
takeRecords(): PerformanceEntryList;
}
type FormDataEntryValue = string | File;
declare class FormData {