Skip to content

Commit

Permalink
feat: property
Browse files Browse the repository at this point in the history
  • Loading branch information
LuciNyan committed Feb 24, 2023
1 parent 60ac636 commit 7d7727a
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/property.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,10 @@ export function hasUnknownProperty<K extends string>(x: unknown, name: K): x is
): x is R {
__GUARD_BY_PROPERTY__ = guardByProperty

const keys = Object.keys(guardByProperty)
const memo = new Set([x])

return keys.every((key) => {
return _hasProperty(x, key, guardByProperty[key], memo)
return Object.entries(guardByProperty).every(([key, guard]) => {
return _hasProperty(x, key, guard, memo)
})
}

Expand All @@ -45,8 +44,9 @@ export function hasUnknownProperty<K extends string>(x: unknown, name: K): x is
guard: (value: unknown) => value is V,
memo = new Set()
): x is { [Key in K]: V } {
if (!hasUnknownProperty(x, name))
return false
if (!hasUnknownProperty(x, name)) {
return false
}

memo.add(x)

Expand All @@ -68,9 +68,7 @@ export function hasUnknownProperty<K extends string>(x: unknown, name: K): x is
): x is R {
memo.add(x)

const keys = Object.keys(guardByProperty)

return keys.every((key) => {
return _hasProperty(x, key, guardByProperty[key], memo)
return Object.entries(guardByProperty).every(([key, guard]) => {
return _hasProperty(x, key, guard, memo)
})
}

0 comments on commit 7d7727a

Please sign in to comment.