Skip to content

Commit

Permalink
Improve type guard/assertion of numericString() (#178)
Browse files Browse the repository at this point in the history
  • Loading branch information
Xananax authored May 30, 2023
1 parent e559b37 commit 888e145
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions source/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ is.boolean = (value: unknown): value is boolean => value === true || value === f

is.symbol = isOfType<symbol>('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 = <T = unknown>(value: unknown, assertion?: (value: T) => value is T): value is T[] => {
Expand Down Expand Up @@ -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: <T = unknown>(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;
Expand Down Expand Up @@ -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: <T = unknown>(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);
Expand Down

0 comments on commit 888e145

Please sign in to comment.