Repository navigation
lib.es2022: hasOwn appears to be defined on Object prototype rather than on constructorΒ #48206
Description
Activity
RyanCavanaugh commented
on Mar 10, 2022 MemberMore actionsThis is an intended UX trade-off in JS files. Since often you'll have untyped variables, we show method help based on name-matching; this way if you're looking for help for a common method name, it shows up even without matching type information.
For more precise behavior, you can turn on
checkJs.See also #33565
- addedWorking as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug
on Mar 10, 2022 Thanks for the reply! I'm seeing this in a TypeScript file in a TypeScript React project when trying to upgrade from 4.3.5 to 4.6.2. Does the same behavior apply?
Let me get a more specific example of the issue I'm running into, one sec.
- removedWorking as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug
on Mar 10, 2022 I ran into this issue because I was trying to upgrade the project from 4.3.5 to 4.6.2. The project has some object types with
hasOwnas a boolean property.e.g.
interface SomeComponentProps { requiredProp: boolean hasOwn?: boolean; }
Using those types started failing to typecheck after the upgrade since TypeScript. For example:
const SomeComponent: React.FC<SomeComponentProps> = () => {} return <SomeComponent requiredProp /> // TS2322: Type '{ requiredProp: boolean }' is not assignable to type 'SomeComponentProps'. Types of property 'hasOwn' are incompatible. Type '(o: object, v: PropertyKey) => boolean' is not assignable to type 'boolean'.
RyanCavanaugh commented
on Mar 10, 2022 MemberMore actionsNo, you're totally right, this is just the lib being wrong. Misread what you were getting at.
No problem! I should've provided the more specific error case up front.
I'm happy to make a PR with test cases for the fix, though it might take me a bit longer since I haven't contributed to TypeScript before. If you'd like to fix this internally that's fine by me.
RyanCavanaugh commented
on Mar 10, 2022 MemberMore actionsI'll put up a PR. Thanks for the report π
Reacted by Derrick Liu- added a commit that references this issue
on Mar 10, 2022 - addedBugA bug in TypeScriptA bug in TypeScriptDomain: lib.d.tsThe issue relates to the different libraries shipped with TypeScriptThe issue relates to the different libraries shipped with TypeScript
on Mar 10, 2022 - added a commit that references this issue
on Mar 10, 2022 - added a commit that references this issue
on Mar 10, 2022 - added a commit that references this issue
on Mar 11, 2022 Do you know if or when this might land in a patch version?
RyanCavanaugh commented
on Mar 16, 2022 MemberMore actionsWe'll be doing a patch release in the next week or two (just waiting to see if other patchworthy things appear first)
Reacted by Rendall- locked as resolved and limited conversation to collaborators
on Oct 22, 2025
Bug Report
π Search Terms
hasOwn, Object.hasOwn, es2022, prototype, lib.es2022.object.d.ts
π Version & Regression Information
Appears to be introduced by #46291
β― Playground Link
Doesn't appear to reproduce on Playground or Bug Workbench, reproduces in VS Code 1.66.0-insider (e80a0ca) running TypeScript 4.6.2.
π» Code
π Actual behavior
I ran into this issue because I was trying to upgrade the project from 4.3.5 to 4.6.2. The project has some object types with
hasOwnas a boolean property.π Expected behavior
hasOwnshould be a method of theObjectconstructor (Object.hasOwn), not the prototype (foo.hasOwn).