@@ -8,7 +8,9 @@ export type EpochMilliseconds = number;
88const hasPerf = ( ) : boolean =>
99 typeof performance !== 'undefined' && typeof performance . now === 'function' ;
1010const hasTimeOrigin = ( ) : boolean =>
11- hasPerf ( ) && typeof ( performance as any ) . timeOrigin === 'number' ;
11+ hasPerf ( ) &&
12+ typeof ( performance as { timeOrigin : number | undefined } ) . timeOrigin ===
13+ 'number' ;
1214
1315const msToUs = ( ms : number ) : Microseconds => Math . round ( ms * 1000 ) ;
1416const usToUs = ( us : number ) : Microseconds => Math . round ( us ) ;
@@ -19,10 +21,10 @@ const usToUs = (us: number): Microseconds => Math.round(us);
1921 * Provides process and thread IDs.
2022 * @param init
2123 */
22- export interface EpochClockOptions {
24+ export type EpochClockOptions = {
2325 pid ?: number ;
2426 tid ?: number ;
25- }
27+ } ;
2628/**
2729 * Creates epoch-based clock utility.
2830 * Epoch time has been the time since January 1, 1970 (UNIX epoch).
@@ -34,20 +36,19 @@ export function epochClock(init: EpochClockOptions = {}) {
3436 const tid = init . tid ?? threadId ;
3537
3638 const timeOriginMs = hasTimeOrigin ( )
37- ? ( ( performance as any ) . timeOrigin as number )
39+ ? ( performance as { timeOrigin : number | undefined } ) . timeOrigin
3840 : undefined ;
3941
4042 const epochNowUs = ( ) : Microseconds => {
4143 if ( hasTimeOrigin ( ) ) {
42- return msToUs ( ( performance as any ) . timeOrigin + performance . now ( ) ) ;
44+ return msToUs ( performance . timeOrigin + performance . now ( ) ) ;
4345 }
4446 return msToUs ( Date . now ( ) ) ;
4547 } ;
4648
47- const fromEpochUs = ( epochUs : Microseconds ) : Microseconds => usToUs ( epochUs ) ;
49+ const fromEpochUs = usToUs ;
4850
49- const fromEpochMs = ( epochMs : EpochMilliseconds ) : Microseconds =>
50- msToUs ( epochMs ) ;
51+ const fromEpochMs = msToUs ;
5152
5253 const fromPerfMs = ( perfMs : Milliseconds ) : Microseconds => {
5354 if ( timeOriginMs === undefined ) {
@@ -56,10 +57,8 @@ export function epochClock(init: EpochClockOptions = {}) {
5657 return msToUs ( timeOriginMs + perfMs ) ;
5758 } ;
5859
59- const fromEntryStartTimeMs = ( startTimeMs : Milliseconds ) : Microseconds =>
60- fromPerfMs ( startTimeMs ) ;
61- const fromDateNowMs = ( dateNowMs : EpochMilliseconds ) : Microseconds =>
62- fromEpochMs ( dateNowMs ) ;
60+ const fromEntryStartTimeMs = fromPerfMs ;
61+ const fromDateNowMs = fromEpochMs ;
6362
6463 return {
6564 timeOriginMs,
0 commit comments