Skip to content

Commit a1fa89a

Browse files
ESLint fixes (renamed all generic params)
1 parent b8db52e commit a1fa89a

File tree

6 files changed

+26
-24
lines changed

6 files changed

+26
-24
lines changed

src/constructor.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ export { constructor as Ono };
1313
function Ono<T extends ErrorLike>(ErrorConstructor: ErrorLikeConstructor<T>, options?: OnoOptions) {
1414
options = normalizeOptions(options);
1515

16-
function ono<E extends ErrorLike, P extends object>(...args: unknown[]) {
17-
let { originalError, props, message } = normalizeArgs<E, P>(args, options!);
16+
function ono<TError extends ErrorLike, TProps extends object>(...args: unknown[]) {
17+
let { originalError, props, message } = normalizeArgs<TError, TProps>(args, options!);
1818

1919
// Create a new error of the specified type
2020
let newError = new (ErrorConstructor as ErrorLikeConstructorClass<T>)(message);

src/extend-error.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ const protectedProps: Array<string | symbol> = ["name", "message", "stack"];
1212
* @param originalError - The original error object, if any
1313
* @param props - Additional properties to add, if any
1414
*/
15-
export function extendError<T extends ErrorLike, E extends ErrorLike, P extends object>(error: T, originalError?: E, props?: P) {
16-
let onoError = error as unknown as T & E & P & OnoError<T & E & P>;
15+
export function extendError<TError extends ErrorLike, TOriginal extends ErrorLike, TProps extends object>(
16+
error: TError, originalError?: TOriginal, props?: TProps) {
17+
18+
let onoError = error as unknown as TError & TOriginal & TProps & OnoError<TError & TOriginal & TProps>;
1719

1820
extendStack(onoError, originalError);
1921

src/normalize.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ export function normalizeOptions(options?: OnoOptions): OnoOptions {
1616
/**
1717
* Normalizes the Ono arguments, accounting for defaults, options, and optional arguments.
1818
*/
19-
export function normalizeArgs<E extends ErrorLike, P extends object>(args: unknown[], options: OnoOptions) {
20-
let originalError: E | undefined;
21-
let props: P | undefined;
19+
export function normalizeArgs<TError extends ErrorLike, TProps extends object>(args: unknown[], options: OnoOptions) {
20+
let originalError: TError | undefined;
21+
let props: TProps | undefined;
2222
let formatArgs: unknown[];
2323
let message = "";
2424

@@ -28,16 +28,16 @@ export function normalizeArgs<E extends ErrorLike, P extends object>(args: unkno
2828
}
2929
else if (typeof args[1] === "string") {
3030
if (args[0] instanceof Error) {
31-
originalError = args[0] as E;
31+
originalError = args[0] as TError;
3232
}
3333
else {
34-
props = args[0] as P;
34+
props = args[0] as TProps;
3535
}
3636
formatArgs = args.slice(1);
3737
}
3838
else {
39-
originalError = args[0] as E;
40-
props = args[1] as P;
39+
originalError = args[0] as TError;
40+
props = args[1] as TProps;
4141
formatArgs = args.slice(2);
4242
}
4343

src/singleton.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const onoMap = ono as unknown as Record<string, Ono<Error>>;
1919
* Creates a new error with the specified message, properties, and/or inner error.
2020
* If an inner error is provided, then the new error will match its type, if possible.
2121
*/
22-
function ono<E extends ErrorLike, P extends object>(...args: unknown[]) {
22+
function ono<TError extends ErrorLike, TProps extends object>(...args: unknown[]) {
2323
let originalError = args[0] as ErrorLike | undefined;
2424

2525
// Is the first argument an Error-like object?

src/to-json.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const objectPrototype = Object.getPrototypeOf({});
88
* Custom JSON serializer for Error objects.
99
* Returns all built-in error properties, as well as extended properties.
1010
*/
11-
export function toJSON<E extends ErrorLike>(this: E): ErrorPOJO & E {
11+
export function toJSON<T extends ErrorLike>(this: T): ErrorPOJO & T {
1212
// HACK: We have to cast the objects to `any` so we can use symbol indexers.
1313
// see https://github.com/Microsoft/TypeScript/issues/1863
1414
let pojo: any = {};
@@ -25,7 +25,7 @@ export function toJSON<E extends ErrorLike>(this: E): ErrorPOJO & E {
2525
}
2626
}
2727

28-
return pojo as ErrorPOJO & E;
28+
return pojo as ErrorPOJO & T;
2929
}
3030

3131

src/types.ts

+10-10
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export interface OnoConstructor {
2424
* Returns an object containing all properties of the given Error object,
2525
* which can be used with `JSON.stringify()`.
2626
*/
27-
toJSON<E extends ErrorLike>(error: E): ErrorPOJO & E;
27+
toJSON<T extends ErrorLike>(error: T): T & ErrorPOJO;
2828

2929
/**
3030
* Extends the given Error object with enhanced Ono functionality, such as improved support for
@@ -41,7 +41,7 @@ export interface OnoConstructor {
4141
* @param error - The error object to extend. This object instance will be modified and returned.
4242
* @param props - An object whose properties will be added to the error
4343
*/
44-
extend<T extends ErrorLike, P extends object>(error: T, props?: P): T & P & OnoError<T & P>;
44+
extend<TError extends ErrorLike, TProps extends object>(error: TError, props?: TProps): TError & TProps & OnoError<TError & TProps>;
4545

4646
/**
4747
* Extends the given Error object with enhanced Ono functionality, such as nested stack traces
@@ -50,7 +50,7 @@ export interface OnoConstructor {
5050
* @param error - The error object to extend. This object instance will be modified and returned.
5151
* @param originalError - The original error. This error's stack trace will be added to the error's stack trace.
5252
*/
53-
extend<T extends ErrorLike, E extends ErrorLike>(error: T, originalError?: E): T & E & OnoError<T & E>;
53+
extend<TError extends ErrorLike, TOriginal extends ErrorLike>(error: TError, originalError?: TOriginal): TError & TOriginal & OnoError<TError & TOriginal>;
5454

5555
/**
5656
* Extends the given Error object with enhanced Ono functionality, such as nested stack traces,
@@ -60,7 +60,7 @@ export interface OnoConstructor {
6060
* @param originalError - The original error. This error's stack trace will be added to the error's stack trace.
6161
* @param props - An object whose properties will be added to the error
6262
*/
63-
extend<T extends ErrorLike, E extends ErrorLike, P extends object>(error: T, originalError?: E, props?: P): T & E & P & OnoError<T & E & P>;
63+
extend<TError extends ErrorLike, TOriginal extends ErrorLike, TProps extends object>(error: TError, originalError?: TOriginal, props?: TProps): TError & TOriginal & TProps & OnoError<TError & TOriginal & TProps>;
6464
}
6565

6666
/**
@@ -77,7 +77,7 @@ export interface Ono<T extends ErrorLike> {
7777
*
7878
* @param error - The original error
7979
*/
80-
<E extends ErrorLike>(error: E): T & E & OnoError<T & E>;
80+
<TError extends ErrorLike>(error: TError): T & TError & OnoError<T & TError>;
8181

8282
/**
8383
* Creates a new error with the message, stack trace, and properties of another error,
@@ -86,7 +86,7 @@ export interface Ono<T extends ErrorLike> {
8686
* @param error - The original error
8787
* @param props - An object whose properties will be added to the returned error
8888
*/
89-
<E extends ErrorLike, P extends object>(error: E, props: P): T & E & P & OnoError<T & E & P>;
89+
<TError extends ErrorLike, TProps extends object>(error: TError, props: TProps): T & TError & TProps & OnoError<T & TError & TProps>;
9090

9191
/**
9292
* Creates a new error with a formatted message and the stack trace and properties of another error.
@@ -95,7 +95,7 @@ export interface Ono<T extends ErrorLike> {
9595
* @param message - The new error message, possibly including argument placeholders
9696
* @param params - Optional arguments to replace the corresponding placeholders in the message
9797
*/
98-
<E extends ErrorLike>(error: E, message: string, ...params: unknown[]): T & E & OnoError<T & E>;
98+
<TError extends ErrorLike>(error: TError, message: string, ...params: unknown[]): T & TError & OnoError<T & TError>;
9999

100100
/**
101101
* Creates a new error with a formatted message and the stack trace and properties of another error,
@@ -106,7 +106,7 @@ export interface Ono<T extends ErrorLike> {
106106
* @param message - The new error message, possibly including argument placeholders
107107
* @param params - Optional arguments to replace the corresponding placeholders in the message
108108
*/
109-
<E extends ErrorLike, P extends object>(error: E, props: P, message: string, ...params: unknown[]): T & E & P & OnoError<T & E & P>;
109+
<TError extends ErrorLike, TProps extends object>(error: TError, props: TProps, message: string, ...params: unknown[]): T & TError & TProps & OnoError<T & TError & TProps>;
110110

111111
/**
112112
* Creates an error with a formatted message.
@@ -121,7 +121,7 @@ export interface Ono<T extends ErrorLike> {
121121
*
122122
* @param props - An object whose properties will be added to the returned error
123123
*/
124-
<P extends object>(props: P): T & P & OnoError<T & P>;
124+
<TProps extends object>(props: TProps): T & TProps & OnoError<T & TProps>;
125125

126126
/**
127127
* Creates an error with a formatted message and additional properties.
@@ -130,7 +130,7 @@ export interface Ono<T extends ErrorLike> {
130130
* @param message - The new error message, possibly including argument placeholders
131131
* @param params - Optional arguments to replace the corresponding placeholders in the message
132132
*/
133-
<P extends object>(props: P, message: string, ...params: unknown[]): T & P & OnoError<T & P>;
133+
<TProps extends object>(props: TProps, message: string, ...params: unknown[]): T & TProps & OnoError<T & TProps>;
134134
}
135135

136136
/**

0 commit comments

Comments
 (0)