diff --git a/source/predicates/predicate.ts b/source/predicates/predicate.ts index f90bfc3..b862b8a 100644 --- a/source/predicates/predicate.ts +++ b/source/predicates/predicate.ts @@ -86,8 +86,9 @@ export class Predicate implements BasePredicate { // We do not include type in this label as we do for other messages, because it would be redundant. const label_ = label?.slice(this.type.length + 1); + // TODO: The NaN check can be removed when `@sindresorhus/is` is fixed: https://github.com/sindresorhus/ow/issues/231#issuecomment-1047100612 // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing - return `Expected ${label_ || 'argument'} to be of type \`${this.type}\` but received type \`${is(value)}\``; + return `Expected ${label_ || 'argument'} to be of type \`${this.type}\` but received type \`${Number.isNaN(value) ? 'NaN' : is(value)}\``; }, // eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-call validator: value => (is as any)[typeString](value), diff --git a/test/number.ts b/test/number.ts index a33f117..5660351 100644 --- a/test/number.ts +++ b/test/number.ts @@ -10,6 +10,10 @@ test('number', t => { ow('12' as any, ow.number); }, {message: 'Expected argument to be of type `number` but received type `string`'}); + t.throws(() => { + ow(Number.NaN as any, ow.number); + }, {message: 'Expected argument to be of type `number` but received type `NaN`'}); + t.throws(() => { ow('12' as any, 'foo', ow.number); }, {message: 'Expected `foo` to be of type `number` but received type `string`'});