Skip to content

PropertyDescriptor (and TypedPropertyDescriptor) should be union of data descriptor and accessor descriptor #61966

Closed as duplicate
@lionel-rowe

Description

@lionel-rowe

🔎 Search Terms

PropertyDescriptor, TypedPropertyDescriptor, getOwnPropertyDescriptor, getOwnPropertyDescriptor, defineProperty, defineProperties

🕗 Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about PropertyDescriptor

⏯ Playground Link

https://www.typescriptlang.org/play/?#code/MYewdgzgLgBADgJxHApgqBPAIiiwECWcUICAXDAApKrra75EkIwC8MA3jAO6FQCGAIwA2KClAQBXFABoYAcxRQAFAEpOMBEskIwMAIwwAvsYBQpgPQWYAASgQAtCgAeqYFCcIkCS9YAqABZI3BAwAEQAwvxgYCCwgnEBMBBuBABmGDD8wMC4EKSh0QAmWTAAbvzC0jCkPHxCollQEgSCklAoYU2akmBQBAC2KKYA8oIAVijuAHRFKGkEYCjUyGiYyhxGcgDkiMjbcnu0mDh4hMSkqqZAA

💻 Code

const propertyDescriptor: PropertyDescriptor = { writable: true, get() { return 1 } }

// @ts-expect-error
Object.defineProperty({}, 'prop', propertyDescriptor)

🙁 Actual behavior

No TS error, only throws "Cannot both specify accessors and a value or writable attribute" at runtime

🙂 Expected behavior

TS disallows invalid descriptors

Additional information about the issue

ECMAScript® 2026 Language Specification - 6.2.6 The Property Descriptor Specification Type (emphasis added):

Property Descriptor values may be further classified as data Property Descriptors and accessor Property Descriptors based upon the existence or use of certain fields. A data Property Descriptor is one that includes any fields named either [[Value]] or [[Writable]]. An accessor Property Descriptor is one that includes any fields named either [[Get]] or [[Set]]. Any Property Descriptor may have fields named [[Enumerable]] and [[Configurable]]. A Property Descriptor value may not be both a data Property Descriptor and an accessor Property Descriptor; however, it may be neither (in which case it is a generic Property Descriptor). A fully populated Property Descriptor is one that is either an accessor Property Descriptor or a data Property Descriptor and that has all of the corresponding fields defined in Table 3.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions