Description
🔎 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
💻 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.