Skip to content

Commit 34201d8

Browse files
rubennortefacebook-github-bot
authored andcommitted
Fix Flow types for performance.measure (#52431)
Summary: Pull Request resolved: #52431 Changelog: [internal] `performance.measure` supports passing mark names as `start` and `end` options, so this fixes the Flow type before fixing the actual implementation. It also makes it so you can't specify both `end` and `duration`, enforced by the type system. Reviewed By: huntie Differential Revision: D77795991 fbshipit-source-id: e89f509c7efc2fa49d17d79bc19bc1d14e007871
1 parent 2edda6d commit 34201d8

File tree

2 files changed

+11
-13
lines changed

2 files changed

+11
-13
lines changed

packages/react-native/src/private/webapis/performance/Performance.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,17 @@ declare var global: {
3838
const getCurrentTimeStamp: () => DOMHighResTimeStamp =
3939
NativePerformance?.now ?? global.nativePerformanceNow ?? (() => Date.now());
4040

41-
export type PerformanceMeasureOptions = {
42-
detail?: DetailType,
43-
start?: DOMHighResTimeStamp,
44-
duration?: DOMHighResTimeStamp,
45-
end?: DOMHighResTimeStamp,
46-
};
41+
export type PerformanceMeasureOptions =
42+
| {
43+
detail?: DetailType,
44+
start?: DOMHighResTimeStamp | string,
45+
duration?: DOMHighResTimeStamp,
46+
}
47+
| {
48+
detail?: DetailType,
49+
start?: DOMHighResTimeStamp | string,
50+
end?: DOMHighResTimeStamp | string,
51+
};
4752

4853
const ENTRY_TYPES_AVAILABLE_FROM_TIMELINE: $ReadOnlyArray<PerformanceEntryType> =
4954
['mark', 'measure'];

packages/react-native/src/private/webapis/performance/__tests__/Performance-itest.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,6 @@ describe('Performance', () => {
159159
startTime: 10,
160160
});
161161

162-
// $FlowFixMe[incompatible-call]
163162
const measure = performance.measure('measure-with-start-mark', {
164163
start: 'start-mark',
165164
});
@@ -179,7 +178,6 @@ describe('Performance', () => {
179178
startTime: 50,
180179
});
181180

182-
// $FlowFixMe[incompatible-call]
183181
const measure = performance.measure('measure-with-end-mark', {
184182
end: 'end-mark',
185183
});
@@ -205,7 +203,6 @@ describe('Performance', () => {
205203

206204
const measure = performance.measure(
207205
'measure-with-start-mark-and-end-mark',
208-
// $FlowFixMe[incompatible-call]
209206
{
210207
start: 'start-mark',
211208
end: 'end-mark',
@@ -263,7 +260,6 @@ describe('Performance', () => {
263260

264261
const measure = performance.measure(
265262
'measure-with-start-mark-and-duration',
266-
// $FlowFixMe[incompatible-call]
267263
{
268264
start: 'start-mark',
269265
duration: 30,
@@ -281,7 +277,6 @@ describe('Performance', () => {
281277
it('throws if the specified mark does NOT exist', () => {
282278
const missingStartMarkError = ensureInstance(
283279
getThrownError(() => {
284-
// $FlowFixMe[incompatible-call]
285280
performance.measure('measure', {
286281
start: 'start',
287282
end: 'end',
@@ -299,7 +294,6 @@ describe('Performance', () => {
299294

300295
const missingEndMarkError = ensureInstance(
301296
getThrownError(() => {
302-
// $FlowFixMe[incompatible-call]
303297
performance.measure('measure', {
304298
start: 'start',
305299
end: 'end',
@@ -314,7 +308,6 @@ describe('Performance', () => {
314308

315309
performance.mark('end');
316310
expect(() => {
317-
// $FlowFixMe[incompatible-call]
318311
performance.measure('measure', {
319312
start: 'start',
320313
end: 'end',

0 commit comments

Comments
 (0)