Skip to content

Commit

Permalink
relax UnknownRecord check, closes #559
Browse files Browse the repository at this point in the history
  • Loading branch information
waynevanson authored Feb 3, 2021
1 parent cd5a1b0 commit eedc197
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export const UnknownArray: Guard<unknown, Array<unknown>> = {
* @since 2.2.0
*/
export const UnknownRecord: Guard<unknown, Record<string, unknown>> = {
is: (u: unknown): u is Record<string, unknown> => Object.prototype.toString.call(u) === '[object Object]'
is: (u: unknown): u is Record<string, unknown> => u != null && typeof u === 'object' && !Array.isArray(u)
}

// -------------------------------------------------------------------------------------
Expand Down
13 changes: 13 additions & 0 deletions test/Guard.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as assert from 'assert'
import * as G from '../src/Guard'
import { pipe } from 'fp-ts/lib/pipeable'
import { Stream } from 'stream'

interface NonEmptyStringBrand {
readonly NonEmptyString: unique symbol
Expand Down Expand Up @@ -281,4 +282,16 @@ describe('Guard', () => {
assert.deepStrictEqual(guard.is({ _tag: 2, b: 'a' }), false)
})
})

describe('UnknownRecord', () => {
it('should accept valid inputs', () => {
assert.strictEqual(G.UnknownRecord.is(new Set()), true)
assert.strictEqual(G.UnknownRecord.is(new Map()), true)
assert.strictEqual(G.UnknownRecord.is(new Stream()), true)
})

it('should reject invalid inputs', () => {
assert.strictEqual(G.UnknownRecord.is([]), false)
})
})
})

0 comments on commit eedc197

Please sign in to comment.