Skip to content

Commit

Permalink
Record / ReadonlyRecord: handle this in hasOwnProperty, fix #1249
Browse files Browse the repository at this point in the history
  • Loading branch information
gcanti committed Jul 1, 2020
1 parent 99c045c commit 0b29bf9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/ReadonlyRecord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,13 @@ export function insertAt<A>(k: string, a: A): (r: ReadonlyRecord<string, A>) =>

const _hasOwnProperty = Object.prototype.hasOwnProperty

// TODO: rename to avoid #1249?
// TODO: rename in v3 to avoid #1249
/**
* @since 2.5.0
*/
export function hasOwnProperty<K extends string>(k: string, r: ReadonlyRecord<K, unknown>): k is K {
return _hasOwnProperty.call(r, k)
export function hasOwnProperty<K extends string>(k: string, r: ReadonlyRecord<K, unknown>): k is K
export function hasOwnProperty<K extends string>(this: any, k: string, r?: ReadonlyRecord<K, unknown>): k is K {
return _hasOwnProperty.call(r === undefined ? this : r, k)
}

/**
Expand Down
5 changes: 5 additions & 0 deletions test/ReadonlyRecord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,11 @@ describe('ReadonlyRecord', () => {
const x: _.ReadonlyRecord<string, number> = { a: 1 }
assert.deepStrictEqual(_.hasOwnProperty('a', x), true)
assert.deepStrictEqual(_.hasOwnProperty('b', x), false)
// TODO: remove in v3
// #1249
const hasOwnProperty: any = _.hasOwnProperty
assert.deepStrictEqual(hasOwnProperty.call(x, 'a'), true)
assert.deepStrictEqual(hasOwnProperty.call(x, 'b'), false)
})

it('updateAt', () => {
Expand Down

0 comments on commit 0b29bf9

Please sign in to comment.