From 5b777bee2c6dd701eb44329eaf5c2f79f26bbaf4 Mon Sep 17 00:00:00 2001 From: farfromrefuge Date: Tue, 24 Sep 2024 10:03:29 +0200 Subject: [PATCH 1/2] chore: update typescript experience now when using `types.isString` for example, typescript will understand that the arg is actually a string and propose intelisense afterward --- packages/core/utils/types.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/core/utils/types.ts b/packages/core/utils/types.ts index 1fba0ae3a2..0bde841ea6 100644 --- a/packages/core/utils/types.ts +++ b/packages/core/utils/types.ts @@ -1,16 +1,16 @@ -export function isString(value: any): boolean { +export function isString(value: any): value is string { return typeof value === 'string' || value instanceof String; } -export function isNumber(value: any): boolean { +export function isNumber(value: any): value is number { return typeof value === 'number' || value instanceof Number; } -export function isBoolean(value: any): boolean { +export function isBoolean(value: any): value is boolean { return typeof value === 'boolean' || value instanceof Boolean; } -export function isFunction(value: any): boolean { +export function isFunction(value: any): value is Function { if (!value) { return false; } @@ -18,7 +18,7 @@ export function isFunction(value: any): boolean { return typeof value === 'function'; } -export function isObject(value: any): boolean { +export function isObject(value: any): value is object { if (!value) { return false; } @@ -26,7 +26,7 @@ export function isObject(value: any): boolean { return typeof value === 'object'; } -export function isUndefined(value: any): boolean { +export function isUndefined(value: any): value is undefined { return typeof value === 'undefined'; } From 10ff999a5fdb457e40115cd9ab3a302e333d56d6 Mon Sep 17 00:00:00 2001 From: farfromrefuge Date: Wed, 2 Oct 2024 14:43:06 +0200 Subject: [PATCH 2/2] fix: isObject to prevent more tsc errors --- packages/core/utils/types.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/utils/types.ts b/packages/core/utils/types.ts index 0bde841ea6..8c2ee145b9 100644 --- a/packages/core/utils/types.ts +++ b/packages/core/utils/types.ts @@ -18,7 +18,7 @@ export function isFunction(value: any): value is Function { return typeof value === 'function'; } -export function isObject(value: any): value is object { +export function isObject(value: any): value is Record { if (!value) { return false; }