From 4d9c1351ed243f8eb7571d6f2bf14a044844a36f Mon Sep 17 00:00:00 2001 From: Xananax Date: Tue, 30 May 2023 13:17:10 +0200 Subject: [PATCH] Discriminate better with `numericString` --- source/index.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/index.ts b/source/index.ts index 1ca92ab..65b579b 100644 --- a/source/index.ts +++ b/source/index.ts @@ -167,7 +167,7 @@ is.boolean = (value: unknown): value is boolean => value === true || value === f is.symbol = isOfType('symbol'); -is.numericString = (value: unknown): value is string => +is.numericString = (value: unknown): value is `${number}` => is.string(value) && !is.emptyStringOrWhitespace(value) && !Number.isNaN(Number(value)); is.array = (value: unknown, assertion?: (value: T) => value is T): value is T[] => { @@ -502,7 +502,7 @@ type Assert = { class_: (value: unknown) => asserts value is Class; boolean: (value: unknown) => asserts value is boolean; symbol: (value: unknown) => asserts value is symbol; - numericString: (value: unknown) => asserts value is string; + numericString: (value: unknown) => asserts value is `${number}`; array: (value: unknown, assertion?: (element: unknown) => asserts element is T) => asserts value is T[]; buffer: (value: unknown) => asserts value is Buffer; blob: (value: unknown) => asserts value is Blob; @@ -600,7 +600,7 @@ export const assert: Assert = { class_: (value: unknown): asserts value is Class => assertType(is.class_(value), AssertionTypeDescription.class_, value), boolean: (value: unknown): asserts value is boolean => assertType(is.boolean(value), 'boolean', value), symbol: (value: unknown): asserts value is symbol => assertType(is.symbol(value), 'symbol', value), - numericString: (value: unknown): asserts value is string => assertType(is.numericString(value), AssertionTypeDescription.numericString, value), + numericString: (value: unknown): asserts value is `${number}` => assertType(is.numericString(value), AssertionTypeDescription.numericString, value), array: (value: unknown, assertion?: (element: unknown) => asserts element is T): asserts value is T[] => { // eslint-disable-line object-shorthand const assert: (condition: boolean, description: string, value: unknown) => asserts condition = assertType; assert(is.array(value), 'Array', value);