From 5b6bb09f56b7dccbe982be239301300048a3ebd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ti=E1=BA=BFn=20Nguy=E1=BB=85n=20Kh=E1=BA=AFc?= Date: Tue, 23 Jul 2024 15:16:33 +1200 Subject: [PATCH] refactor: use `this` to instantiate new instance of the same class --- packages/core/src/errors.ts | 16 ++++------------ packages/react/src/utils/jotai.ts | 4 ++-- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/packages/core/src/errors.ts b/packages/core/src/errors.ts index b00c5b33..ad3f37e1 100644 --- a/packages/core/src/errors.ts +++ b/packages/core/src/errors.ts @@ -1,17 +1,9 @@ export class ReDotError extends Error { - static from(error: T, message?: string): ReDotError { - return new ReDotError(message, { cause: error }); + static from(error: T, message?: string) { + return new this(message, { cause: error }); } } -export class QueryError extends ReDotError { - static override from(error: T, message?: string): QueryError { - return new QueryError(message, { cause: error }); - } -} +export class QueryError extends ReDotError {} -export class MutationError extends ReDotError { - static override from(error: T, message?: string): MutationError { - return new MutationError(message, { cause: error }); - } -} +export class MutationError extends ReDotError {} diff --git a/packages/react/src/utils/jotai.ts b/packages/react/src/utils/jotai.ts index 8f2529a3..b3314f0f 100644 --- a/packages/react/src/utils/jotai.ts +++ b/packages/react/src/utils/jotai.ts @@ -22,8 +22,8 @@ export class AtomFamilyError extends QueryError { ? Param : unknown, message?: string, - ): AtomFamilyError { - return new AtomFamilyError(atomFamily, param, message, { + ) { + return new this(atomFamily, param, message, { cause: error, }); }