Skip to content

Commit 8cafbe7

Browse files
committed
feat: added AnyFn type to types.ts to replace repeated usage
1 parent 1ce7168 commit 8cafbe7

File tree

4 files changed

+7
-10
lines changed

4 files changed

+7
-10
lines changed

src/CreateDestroy.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Status, Class } from './types.js';
1+
import type { Status, Class, AnyFn } from './types.js';
22
import { Evented } from '@matrixai/events';
33
import { RWLockWriter } from '@matrixai/async-locks';
44
import {
@@ -118,7 +118,6 @@ function ready(
118118
} else if (descriptor.set != null) {
119119
kind = 'set';
120120
}
121-
type AnyFn = (...args: Array<unknown>) => unknown;
122121
const f = descriptor[kind] as AnyFn;
123122
if (typeof f !== 'function') {
124123
throw new TypeError(`${key} is not a function`);

src/CreateDestroyStartStop.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Status, Class } from './types.js';
1+
import type { Status, Class, AnyFn } from './types.js';
22
import { Evented } from '@matrixai/events';
33
import { RWLockWriter } from '@matrixai/async-locks';
44
import {
@@ -238,7 +238,6 @@ function ready(
238238
} else if (descriptor.set != null) {
239239
kind = 'set';
240240
}
241-
type AnyFn = (...args: Array<unknown>) => unknown;
242241
const f = descriptor[kind] as AnyFn;
243242
if (typeof f !== 'function') {
244243
throw new TypeError(`${key} is not a function`);

src/types.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,6 @@ type Status = 'destroying' | 'starting' | 'stopping' | null;
1111

1212
type Class<T> = new (...args: any[]) => T;
1313

14-
export type { PromiseDeconstructed, Status, Class };
14+
type AnyFn = (...args: Array<unknown>) => unknown;
15+
16+
export type { PromiseDeconstructed, Status, Class, AnyFn };

src/utils.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { PromiseDeconstructed } from './types.js';
1+
import type { AnyFn, PromiseDeconstructed } from './types.js';
22

33
/**
44
* Symbols prevents name clashes with decorated classes
@@ -42,10 +42,7 @@ function promise<T = void>(): PromiseDeconstructed<T> {
4242
* This function rewrites the stack trace according to where the wrapped
4343
* function is called, giving a more useful stack trace
4444
*/
45-
function resetStackTrace(
46-
error: Error,
47-
decorated?: (...args: Array<unknown>) => unknown,
48-
): void {
45+
function resetStackTrace(error: Error, decorated?: AnyFn): void {
4946
if (error.stack != null) {
5047
const stackTitle = error.stack.slice(0, error.stack.indexOf('\n') + 1);
5148
if (hasCaptureStackTrace) {

0 commit comments

Comments
 (0)