From 37e097dd5f987410603d08f2cea066f4978f1e40 Mon Sep 17 00:00:00 2001 From: Filip Skokan Date: Mon, 21 Feb 2022 18:45:25 +0100 Subject: [PATCH] Fix NaN .is() return --- 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 fcd66a0..0d4bc0a 100644 --- a/source/index.ts +++ b/source/index.ts @@ -50,6 +50,7 @@ const objectTypeNames = [ 'FormData', 'URLSearchParams', 'HTMLElement', + 'NaN', ...typedArrayTypeNames ] as const; @@ -110,7 +111,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 734fd27..a177e87 100644 --- a/test/test.ts +++ b/test/test.ts @@ -446,7 +446,7 @@ const types = new Map([ NaN, Number.NaN ], - typename: 'number', + typename: 'NaN', typeDescription: AssertionTypeDescription.nan }], ['nullOrUndefined', {