Skip to content

Commit

Permalink
Fix NaN detection in .is() (#159)
Browse files Browse the repository at this point in the history
  • Loading branch information
panva committed Jun 9, 2022
1 parent 65ea912 commit c408f5a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion source/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const objectTypeNames = [
'FormData',
'URLSearchParams',
'HTMLElement',
'NaN',
...typedArrayTypeNames
] as const;

Expand Down Expand Up @@ -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':
Expand Down
2 changes: 1 addition & 1 deletion test/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ const types = new Map<string, Test>([
NaN,
Number.NaN
],
typename: 'number',
typename: 'NaN',
typeDescription: AssertionTypeDescription.nan
}],
['nullOrUndefined', {
Expand Down

0 comments on commit c408f5a

Please sign in to comment.