Skip to content

lib.es2022: hasOwn appears to be defined on Object prototype rather than on constructorΒ #48206

Closed
@lediur

Description

@lediur

Bug Report

πŸ”Ž Search Terms

hasOwn, Object.hasOwn, es2022, prototype, lib.es2022.object.d.ts

πŸ•— Version & Regression Information

  • This changed between versions 4.2.4 and 4.6.2

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

interface SomeComponentProps {
  requiredProp: boolean
  hasOwn?: boolean;
}

const SomeComponent: React.FC<SomeComponentProps> = () => {}

return <SomeComponent requiredProp />

πŸ™ 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 hasOwn as a boolean property.

// 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'.

πŸ™‚ Expected behavior

hasOwn should be a method of the Object constructor (Object.hasOwn), not the prototype (foo.hasOwn).

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDomain: lib.d.tsThe issue relates to the different libraries shipped with TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions