From c408f5a2680b750c8a000289954dacc2296acc00 Mon Sep 17 00:00:00 2001 From: Filip Skokan Date: Thu, 9 Jun 2022 19:05:31 +0200 Subject: [PATCH] Fix `NaN` detection in `.is()` (#159) --- source/index.ts | 3 ++- test/test.ts | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/source/index.ts b/source/index.ts index 5ce333d..39e5883 100644 --- a/source/index.ts +++ b/source/index.ts @@ -51,6 +51,7 @@ const objectTypeNames = [ 'FormData', 'URLSearchParams', 'HTMLElement', + 'NaN', ...typedArrayTypeNames ] as const; @@ -111,7 +112,7 @@ function is(value: unknown): TypeName { case 'string': return 'string'; case 'number': - return 'number'; + return Number.isNaN(value) ? 'NaN' : 'number'; case 'boolean': return 'boolean'; case 'function': diff --git a/test/test.ts b/test/test.ts index 71a4a9d..f4fe213 100644 --- a/test/test.ts +++ b/test/test.ts @@ -454,7 +454,7 @@ const types = new Map([ NaN, Number.NaN ], - typename: 'number', + typename: 'NaN', typeDescription: AssertionTypeDescription.nan }], ['nullOrUndefined', {