Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: return type predicate #3

Closed
privatenumber opened this issue Oct 27, 2021 · 2 comments · Fixed by #4
Closed

feat: return type predicate #3

privatenumber opened this issue Oct 27, 2021 · 2 comments · Fixed by #4

Comments

@privatenumber
Copy link
Sponsor Contributor

I read this blogpost by @ddprrt that offered a solution to making a custom hasOwnProperty that returns a type predicate:

function hasOwnProperty<X extends {}, Y extends PropertyKey>
  (obj: X, prop: Y): obj is X & Record<Y, unknown> {
  return obj.hasOwnProperty(prop)
}

The type will diverge from TypeScript's native hasOwnProperty type, but what do you think of this enhancement?

@sindresorhus
Copy link
Owner

👍 PR welcome.

@ddprrt
Copy link

ddprrt commented Nov 2, 2021

Cool! 👏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants