Skip to content

Commit

Permalink
Accept generics for defineProperty (#42424)
Browse files Browse the repository at this point in the history
* Accept generics for defineProperty

Both `Object.defineProperty()` and `Object.defineProperties()` return their
first argument. Use a generic so that typings can be passed through.

* Update baselines

* update missed baseline

Co-authored-by: Nathan Shively-Sanders <[email protected]>
  • Loading branch information
sirlancelot and sandersn authored Mar 11, 2021
1 parent 71661b9 commit dcaefe7
Show file tree
Hide file tree
Showing 21 changed files with 174 additions and 174 deletions.
4 changes: 2 additions & 2 deletions src/lib/es5.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,14 +177,14 @@ interface ObjectConstructor {
* @param p The property name.
* @param attributes Descriptor for the property. It can be for a data property or an accessor property.
*/
defineProperty(o: any, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>): any;
defineProperty<T>(o: T, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>): T;

/**
* Adds one or more properties to an object, and/or modifies attributes of existing properties.
* @param o Object on which to add or modify the properties. This can be a native JavaScript object or a DOM object.
* @param properties JavaScript object that contains one or more descriptor objects. Each descriptor object describes a data property or an accessor property.
*/
defineProperties(o: any, properties: PropertyDescriptorMap & ThisType<any>): any;
defineProperties<T>(o: T, properties: PropertyDescriptorMap & ThisType<any>): T;

/**
* Prevents the modification of attributes of existing properties, and prevents the addition of new properties.
Expand Down
60 changes: 30 additions & 30 deletions tests/baselines/reference/checkExportsObjectAssignProperty.types
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,10 @@ m2.setonlyAccessor = 0;

=== tests/cases/conformance/jsdoc/mod1.js ===
Object.defineProperty(exports, "thing", { value: 42, writable: true });
>Object.defineProperty(exports, "thing", { value: 42, writable: true }) : any
>Object.defineProperty : (o: any, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => any
>Object.defineProperty(exports, "thing", { value: 42, writable: true }) : typeof import("tests/cases/conformance/jsdoc/mod1")
>Object.defineProperty : <T>(o: T, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => T
>Object : ObjectConstructor
>defineProperty : (o: any, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => any
>defineProperty : <T>(o: T, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => T
>exports : typeof import("tests/cases/conformance/jsdoc/mod1")
>"thing" : "thing"
>{ value: 42, writable: true } : { value: number; writable: true; }
Expand All @@ -188,10 +188,10 @@ Object.defineProperty(exports, "thing", { value: 42, writable: true });
>true : true

Object.defineProperty(exports, "readonlyProp", { value: "Smith", writable: false });
>Object.defineProperty(exports, "readonlyProp", { value: "Smith", writable: false }) : any
>Object.defineProperty : (o: any, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => any
>Object.defineProperty(exports, "readonlyProp", { value: "Smith", writable: false }) : typeof import("tests/cases/conformance/jsdoc/mod1")
>Object.defineProperty : <T>(o: T, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => T
>Object : ObjectConstructor
>defineProperty : (o: any, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => any
>defineProperty : <T>(o: T, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => T
>exports : typeof import("tests/cases/conformance/jsdoc/mod1")
>"readonlyProp" : "readonlyProp"
>{ value: "Smith", writable: false } : { value: string; writable: false; }
Expand All @@ -201,10 +201,10 @@ Object.defineProperty(exports, "readonlyProp", { value: "Smith", writable: false
>false : false

Object.defineProperty(exports, "rwAccessors", { get() { return 98122 }, set(_) { /*ignore*/ } });
>Object.defineProperty(exports, "rwAccessors", { get() { return 98122 }, set(_) { /*ignore*/ } }) : any
>Object.defineProperty : (o: any, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => any
>Object.defineProperty(exports, "rwAccessors", { get() { return 98122 }, set(_) { /*ignore*/ } }) : typeof import("tests/cases/conformance/jsdoc/mod1")
>Object.defineProperty : <T>(o: T, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => T
>Object : ObjectConstructor
>defineProperty : (o: any, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => any
>defineProperty : <T>(o: T, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => T
>exports : typeof import("tests/cases/conformance/jsdoc/mod1")
>"rwAccessors" : "rwAccessors"
>{ get() { return 98122 }, set(_) { /*ignore*/ } } : { get(): number; set(_: any): void; }
Expand All @@ -214,21 +214,21 @@ Object.defineProperty(exports, "rwAccessors", { get() { return 98122 }, set(_) {
>_ : any

Object.defineProperty(exports, "readonlyAccessor", { get() { return 21.75 } });
>Object.defineProperty(exports, "readonlyAccessor", { get() { return 21.75 } }) : any
>Object.defineProperty : (o: any, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => any
>Object.defineProperty(exports, "readonlyAccessor", { get() { return 21.75 } }) : typeof import("tests/cases/conformance/jsdoc/mod1")
>Object.defineProperty : <T>(o: T, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => T
>Object : ObjectConstructor
>defineProperty : (o: any, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => any
>defineProperty : <T>(o: T, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => T
>exports : typeof import("tests/cases/conformance/jsdoc/mod1")
>"readonlyAccessor" : "readonlyAccessor"
>{ get() { return 21.75 } } : { get(): number; }
>get : () => number
>21.75 : 21.75

Object.defineProperty(exports, "setonlyAccessor", {
>Object.defineProperty(exports, "setonlyAccessor", { /** @param {string} str */ set(str) { this.rwAccessors = Number(str) }}) : any
>Object.defineProperty : (o: any, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => any
>Object.defineProperty(exports, "setonlyAccessor", { /** @param {string} str */ set(str) { this.rwAccessors = Number(str) }}) : typeof import("tests/cases/conformance/jsdoc/mod1")
>Object.defineProperty : <T>(o: T, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => T
>Object : ObjectConstructor
>defineProperty : (o: any, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => any
>defineProperty : <T>(o: T, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => T
>exports : typeof import("tests/cases/conformance/jsdoc/mod1")
>"setonlyAccessor" : "setonlyAccessor"
>{ /** @param {string} str */ set(str) { this.rwAccessors = Number(str) }} : { set(str: string): void; }
Expand All @@ -251,10 +251,10 @@ Object.defineProperty(exports, "setonlyAccessor", {

=== tests/cases/conformance/jsdoc/mod2.js ===
Object.defineProperty(module.exports, "thing", { value: "yes", writable: true });
>Object.defineProperty(module.exports, "thing", { value: "yes", writable: true }) : any
>Object.defineProperty : (o: any, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => any
>Object.defineProperty(module.exports, "thing", { value: "yes", writable: true }) : typeof module.exports
>Object.defineProperty : <T>(o: T, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => T
>Object : ObjectConstructor
>defineProperty : (o: any, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => any
>defineProperty : <T>(o: T, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => T
>module.exports : typeof module.exports
>module : { exports: typeof module.exports; }
>exports : typeof module.exports
Expand All @@ -266,10 +266,10 @@ Object.defineProperty(module.exports, "thing", { value: "yes", writable: true })
>true : true

Object.defineProperty(module.exports, "readonlyProp", { value: "Smith", writable: false });
>Object.defineProperty(module.exports, "readonlyProp", { value: "Smith", writable: false }) : any
>Object.defineProperty : (o: any, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => any
>Object.defineProperty(module.exports, "readonlyProp", { value: "Smith", writable: false }) : typeof module.exports
>Object.defineProperty : <T>(o: T, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => T
>Object : ObjectConstructor
>defineProperty : (o: any, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => any
>defineProperty : <T>(o: T, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => T
>module.exports : typeof module.exports
>module : { exports: typeof module.exports; }
>exports : typeof module.exports
Expand All @@ -281,10 +281,10 @@ Object.defineProperty(module.exports, "readonlyProp", { value: "Smith", writable
>false : false

Object.defineProperty(module.exports, "rwAccessors", { get() { return 98122 }, set(_) { /*ignore*/ } });
>Object.defineProperty(module.exports, "rwAccessors", { get() { return 98122 }, set(_) { /*ignore*/ } }) : any
>Object.defineProperty : (o: any, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => any
>Object.defineProperty(module.exports, "rwAccessors", { get() { return 98122 }, set(_) { /*ignore*/ } }) : typeof module.exports
>Object.defineProperty : <T>(o: T, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => T
>Object : ObjectConstructor
>defineProperty : (o: any, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => any
>defineProperty : <T>(o: T, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => T
>module.exports : typeof module.exports
>module : { exports: typeof module.exports; }
>exports : typeof module.exports
Expand All @@ -296,10 +296,10 @@ Object.defineProperty(module.exports, "rwAccessors", { get() { return 98122 }, s
>_ : any

Object.defineProperty(module.exports, "readonlyAccessor", { get() { return 21.75 } });
>Object.defineProperty(module.exports, "readonlyAccessor", { get() { return 21.75 } }) : any
>Object.defineProperty : (o: any, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => any
>Object.defineProperty(module.exports, "readonlyAccessor", { get() { return 21.75 } }) : typeof module.exports
>Object.defineProperty : <T>(o: T, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => T
>Object : ObjectConstructor
>defineProperty : (o: any, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => any
>defineProperty : <T>(o: T, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => T
>module.exports : typeof module.exports
>module : { exports: typeof module.exports; }
>exports : typeof module.exports
Expand All @@ -309,10 +309,10 @@ Object.defineProperty(module.exports, "readonlyAccessor", { get() { return 21.75
>21.75 : 21.75

Object.defineProperty(module.exports, "setonlyAccessor", {
>Object.defineProperty(module.exports, "setonlyAccessor", { /** @param {string} str */ set(str) { this.rwAccessors = Number(str) }}) : any
>Object.defineProperty : (o: any, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => any
>Object.defineProperty(module.exports, "setonlyAccessor", { /** @param {string} str */ set(str) { this.rwAccessors = Number(str) }}) : typeof module.exports
>Object.defineProperty : <T>(o: T, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => T
>Object : ObjectConstructor
>defineProperty : (o: any, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => any
>defineProperty : <T>(o: T, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => T
>module.exports : typeof module.exports
>module : { exports: typeof module.exports; }
>exports : typeof module.exports
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,9 @@ Person.prototype.describe = function () {
};
Object.defineProperty(Person.prototype, "thing", { value: 42, writable: true });
>Object.defineProperty(Person.prototype, "thing", { value: 42, writable: true }) : any
>Object.defineProperty : (o: any, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => any
>Object.defineProperty : <T>(o: T, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => T
>Object : ObjectConstructor
>defineProperty : (o: any, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => any
>defineProperty : <T>(o: T, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => T
>Person.prototype : any
>Person : typeof Person
>prototype : any
Expand All @@ -144,9 +144,9 @@ Object.defineProperty(Person.prototype, "thing", { value: 42, writable: true });

Object.defineProperty(Person.prototype, "readonlyProp", { value: "Smith", writable: false });
>Object.defineProperty(Person.prototype, "readonlyProp", { value: "Smith", writable: false }) : any
>Object.defineProperty : (o: any, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => any
>Object.defineProperty : <T>(o: T, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => T
>Object : ObjectConstructor
>defineProperty : (o: any, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => any
>defineProperty : <T>(o: T, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => T
>Person.prototype : any
>Person : typeof Person
>prototype : any
Expand All @@ -159,9 +159,9 @@ Object.defineProperty(Person.prototype, "readonlyProp", { value: "Smith", writab

Object.defineProperty(Person.prototype, "rwAccessors", { get() { return 98122 }, set(_) { /*ignore*/ } });
>Object.defineProperty(Person.prototype, "rwAccessors", { get() { return 98122 }, set(_) { /*ignore*/ } }) : any
>Object.defineProperty : (o: any, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => any
>Object.defineProperty : <T>(o: T, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => T
>Object : ObjectConstructor
>defineProperty : (o: any, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => any
>defineProperty : <T>(o: T, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => T
>Person.prototype : any
>Person : typeof Person
>prototype : any
Expand All @@ -174,9 +174,9 @@ Object.defineProperty(Person.prototype, "rwAccessors", { get() { return 98122 },

Object.defineProperty(Person.prototype, "readonlyAccessor", { get() { return 21.75 } });
>Object.defineProperty(Person.prototype, "readonlyAccessor", { get() { return 21.75 } }) : any
>Object.defineProperty : (o: any, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => any
>Object.defineProperty : <T>(o: T, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => T
>Object : ObjectConstructor
>defineProperty : (o: any, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => any
>defineProperty : <T>(o: T, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => T
>Person.prototype : any
>Person : typeof Person
>prototype : any
Expand All @@ -187,9 +187,9 @@ Object.defineProperty(Person.prototype, "readonlyAccessor", { get() { return 21.

Object.defineProperty(Person.prototype, "setonlyAccessor", {
>Object.defineProperty(Person.prototype, "setonlyAccessor", { /** @param {string} str */ set(str) { this.rwAccessors = Number(str) }}) : any
>Object.defineProperty : (o: any, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => any
>Object.defineProperty : <T>(o: T, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => T
>Object : ObjectConstructor
>defineProperty : (o: any, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => any
>defineProperty : <T>(o: T, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => T
>Person.prototype : any
>Person : typeof Person
>prototype : any
Expand Down
Loading

0 comments on commit dcaefe7

Please sign in to comment.