File tree Expand file tree Collapse file tree 2 files changed +14
-1
lines changed
Expand file tree Collapse file tree 2 files changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -93,7 +93,7 @@ export const UnknownArray: Guard<unknown, Array<unknown>> = {
9393 * @since 2.2.0
9494 */
9595export const UnknownRecord : Guard < unknown , Record < string , unknown > > = {
96- is : ( u : unknown ) : u is Record < string , unknown > => Object . prototype . toString . call ( u ) === '[ object Object]'
96+ is : ( u : unknown ) : u is Record < string , unknown > => u != null && typeof u === ' object' && ! Array . isArray ( u )
9797}
9898
9999// -------------------------------------------------------------------------------------
Original file line number Diff line number Diff line change 11import * as assert from 'assert'
22import * as G from '../src/Guard'
33import { pipe } from 'fp-ts/lib/pipeable'
4+ import { Stream } from 'stream'
45
56interface NonEmptyStringBrand {
67 readonly NonEmptyString : unique symbol
@@ -281,4 +282,16 @@ describe('Guard', () => {
281282 assert . deepStrictEqual ( guard . is ( { _tag : 2 , b : 'a' } ) , false )
282283 } )
283284 } )
285+
286+ describe ( 'UnknownRecord' , ( ) => {
287+ it ( 'should accept valid inputs' , ( ) => {
288+ assert . strictEqual ( G . UnknownRecord . is ( new Set ( ) ) , true )
289+ assert . strictEqual ( G . UnknownRecord . is ( new Map ( ) ) , true )
290+ assert . strictEqual ( G . UnknownRecord . is ( new Stream ( ) ) , true )
291+ } )
292+
293+ it ( 'should reject invalid inputs' , ( ) => {
294+ assert . strictEqual ( G . UnknownRecord . is ( [ ] ) , false )
295+ } )
296+ } )
284297} )
You can’t perform that action at this time.
0 commit comments