Skip to content

Commit 8b640be

Browse files
lib Types and Documentations Fix
1 parent 8d7ad8c commit 8b640be

File tree

71 files changed

+1153
-317
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+1153
-317
lines changed

src/harness/fourslashInterfaceImpl.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,6 +1172,7 @@ namespace FourSlashInterface {
11721172
typeEntry("Partial"),
11731173
typeEntry("Required"),
11741174
typeEntry("Readonly"),
1175+
typeEntry("Writable"),
11751176
typeEntry("Pick"),
11761177
typeEntry("Record"),
11771178
typeEntry("Exclude"),

src/lib/es2015.core.d.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -257,13 +257,20 @@ interface NumberConstructor {
257257
}
258258

259259
interface ObjectConstructor {
260+
/**
261+
* Copy the values of all of the enumerable own properties from one or more source objects to a
262+
* target object. Returns the target object.
263+
* @param target The target object to copy to.
264+
*/
265+
assign<T extends {}>(target: T): T;
266+
260267
/**
261268
* Copy the values of all of the enumerable own properties from one or more source objects to a
262269
* target object. Returns the target object.
263270
* @param target The target object to copy to.
264271
* @param source The source object from which to copy properties.
265272
*/
266-
assign<T extends {}, U>(target: T, source: U): T & U;
273+
assign<T extends {}, U>(target: T, source: U): T & Writable<U>;
267274

268275
/**
269276
* Copy the values of all of the enumerable own properties from one or more source objects to a
@@ -272,7 +279,7 @@ interface ObjectConstructor {
272279
* @param source1 The first source object from which to copy properties.
273280
* @param source2 The second source object from which to copy properties.
274281
*/
275-
assign<T extends {}, U, V>(target: T, source1: U, source2: V): T & U & V;
282+
assign<T extends {}, U, V>(target: T, source1: U, source2: V): T & Writable<U> & Writable<V>;
276283

277284
/**
278285
* Copy the values of all of the enumerable own properties from one or more source objects to a
@@ -282,21 +289,21 @@ interface ObjectConstructor {
282289
* @param source2 The second source object from which to copy properties.
283290
* @param source3 The third source object from which to copy properties.
284291
*/
285-
assign<T extends {}, U, V, W>(target: T, source1: U, source2: V, source3: W): T & U & V & W;
292+
assign<T extends {}, U, V, W>(target: T, source1: U, source2: V, source3: W): T & Writable<U> & Writable<V> & Writable<W>;
286293

287294
/**
288295
* Copy the values of all of the enumerable own properties from one or more source objects to a
289296
* target object. Returns the target object.
290297
* @param target The target object to copy to.
291-
* @param sources One or more source objects from which to copy properties
298+
* @param sources One or more source objects from which to copy properties.
292299
*/
293-
assign(target: object, ...sources: any[]): any;
300+
assign(target: {}, ...sources: any[]): any;
294301

295302
/**
296303
* Returns an array of all symbol properties found directly on object o.
297304
* @param o Object to retrieve the symbols from.
298305
*/
299-
getOwnPropertySymbols(o: any): symbol[];
306+
getOwnPropertySymbols(o: {}): symbol[];
300307

301308
/**
302309
* Returns the names of the enumerable string properties and methods of an object.
@@ -316,7 +323,7 @@ interface ObjectConstructor {
316323
* @param o The object to change its prototype.
317324
* @param proto The value of the new prototype or null.
318325
*/
319-
setPrototypeOf(o: any, proto: object | null): any;
326+
setPrototypeOf(o: {}, proto: object | null): any;
320327
}
321328

322329
interface ReadonlyArray<T> {

src/lib/es2017.object.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@ interface ObjectConstructor {
2727
* Returns an object containing all own property descriptors of an object
2828
* @param o Object that contains the properties and methods. This can be an object that you created or an existing Document Object Model (DOM) object.
2929
*/
30-
getOwnPropertyDescriptors<T>(o: T): {[P in keyof T]: TypedPropertyDescriptor<T[P]>} & { [x: string]: PropertyDescriptor };
30+
getOwnPropertyDescriptors<T extends {}>(o: T): { [P in keyof T]: TypedPropertyDescriptor<T[P]> } & PropertyDescriptorMap;
3131
}

src/lib/es2019.object.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ interface ObjectConstructor {
55
* Returns an object created by key-value entries for properties and methods
66
* @param entries An iterable object that contains key-value entries for properties and methods.
77
*/
8-
fromEntries<T = any>(entries: Iterable<readonly [PropertyKey, T]>): { [k: string]: T };
8+
fromEntries<T = any>(entries: Iterable<readonly [PropertyKey, T]>): { [k: PropertyKey]: T };
99

1010
/**
1111
* Returns an object created by key-value entries for properties and methods

src/lib/es2022.object.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ interface ObjectConstructor {
44
* @param o An object.
55
* @param v A property name.
66
*/
7-
hasOwn(o: object, v: PropertyKey): boolean;
7+
hasOwn(o: {}, v: PropertyKey): boolean;
88
}

src/lib/es5.d.ts

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -143,22 +143,22 @@ interface ObjectConstructor {
143143
* Returns the prototype of an object.
144144
* @param o The object that references the prototype.
145145
*/
146-
getPrototypeOf(o: any): any;
146+
getPrototypeOf(o: {}): any;
147147

148148
/**
149149
* Gets the own property descriptor of the specified object.
150150
* An own property descriptor is one that is defined directly on the object and is not inherited from the object's prototype.
151151
* @param o Object that contains the property.
152152
* @param p Name of the property.
153153
*/
154-
getOwnPropertyDescriptor(o: any, p: PropertyKey): PropertyDescriptor | undefined;
154+
getOwnPropertyDescriptor(o: {}, p: PropertyKey): PropertyDescriptor | undefined;
155155

156156
/**
157157
* Returns the names of the own properties of an object. The own properties of an object are those that are defined directly
158158
* on that object, and are not inherited from the object's prototype. The properties of an object include both fields (objects) and functions.
159159
* @param o Object that contains the own properties.
160160
*/
161-
getOwnPropertyNames(o: any): string[];
161+
getOwnPropertyNames(o: {}): string[];
162162

163163
/**
164164
* Creates an object that has the specified prototype or that has null prototype.
@@ -179,14 +179,14 @@ interface ObjectConstructor {
179179
* @param p The property name.
180180
* @param attributes Descriptor for the property. It can be for a data property or an accessor property.
181181
*/
182-
defineProperty<T>(o: T, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>): T;
182+
defineProperty<T extends object>(o: T, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>): T;
183183

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

191191
/**
192192
* Prevents the modification of attributes of existing properties, and prevents the addition of new properties.
@@ -204,7 +204,7 @@ interface ObjectConstructor {
204204
* Prevents the modification of existing property attributes and values, and prevents the addition of new properties.
205205
* @param o Object on which to lock the attributes.
206206
*/
207-
freeze<T extends {[idx: string]: U | null | undefined | object}, U extends string | bigint | number | boolean | symbol>(o: T): Readonly<T>;
207+
freeze<T extends { [idx: string]: U | null | undefined | object }, U extends string | bigint | number | boolean | symbol>(o: T): Readonly<T>;
208208

209209
/**
210210
* Prevents the modification of existing property attributes and values, and prevents the addition of new properties.
@@ -222,19 +222,37 @@ interface ObjectConstructor {
222222
* Returns true if existing property attributes cannot be modified in an object and new properties cannot be added to the object.
223223
* @param o Object to test.
224224
*/
225-
isSealed(o: any): boolean;
225+
isSealed(o: object): boolean;
226+
227+
/**
228+
* Returns true if existing property attributes cannot be modified in an object and new properties cannot be added to the object.
229+
* @param o Object to test.
230+
*/
231+
isSealed(o: any): true;
232+
233+
/**
234+
* Returns true if existing property attributes and values cannot be modified in an object, and new properties cannot be added to the object.
235+
* @param o Object to test.
236+
*/
237+
isFrozen(o: object): boolean;
226238

227239
/**
228240
* Returns true if existing property attributes and values cannot be modified in an object, and new properties cannot be added to the object.
229241
* @param o Object to test.
230242
*/
231-
isFrozen(o: any): boolean;
243+
isFrozen(o: any): true;
232244

233245
/**
234246
* Returns a value that indicates whether new properties can be added to an object.
235247
* @param o Object to test.
236248
*/
237-
isExtensible(o: any): boolean;
249+
isExtensible(o: object): boolean;
250+
251+
/**
252+
* Returns a value that indicates whether new properties can be added to an object.
253+
* @param o Object to test.
254+
*/
255+
isExtensible(o: any): false;
238256

239257
/**
240258
* Returns the names of the enumerable string properties and methods of an object.
@@ -1552,6 +1570,13 @@ type Readonly<T> = {
15521570
readonly [P in keyof T]: T[P];
15531571
};
15541572

1573+
/**
1574+
* Make all properties in T writable
1575+
*/
1576+
type Writable<T> = {
1577+
-readonly [P in keyof T]: T[P];
1578+
};
1579+
15551580
/**
15561581
* From T, pick a set of properties whose keys are in the union K
15571582
*/

tests/baselines/reference/checkExportsObjectAssignProperty.types

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,9 @@ m2.setonlyAccessor = 0;
176176
=== tests/cases/conformance/jsdoc/mod1.js ===
177177
Object.defineProperty(exports, "thing", { value: 42, writable: true });
178178
>Object.defineProperty(exports, "thing", { value: 42, writable: true }) : typeof import("tests/cases/conformance/jsdoc/mod1")
179-
>Object.defineProperty : <T>(o: T, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => T
179+
>Object.defineProperty : <T extends object>(o: T, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => T
180180
>Object : ObjectConstructor
181-
>defineProperty : <T>(o: T, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => T
181+
>defineProperty : <T extends object>(o: T, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => T
182182
>exports : typeof import("tests/cases/conformance/jsdoc/mod1")
183183
>"thing" : "thing"
184184
>{ value: 42, writable: true } : { value: number; writable: true; }
@@ -189,9 +189,9 @@ Object.defineProperty(exports, "thing", { value: 42, writable: true });
189189

190190
Object.defineProperty(exports, "readonlyProp", { value: "Smith", writable: false });
191191
>Object.defineProperty(exports, "readonlyProp", { value: "Smith", writable: false }) : typeof import("tests/cases/conformance/jsdoc/mod1")
192-
>Object.defineProperty : <T>(o: T, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => T
192+
>Object.defineProperty : <T extends object>(o: T, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => T
193193
>Object : ObjectConstructor
194-
>defineProperty : <T>(o: T, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => T
194+
>defineProperty : <T extends object>(o: T, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => T
195195
>exports : typeof import("tests/cases/conformance/jsdoc/mod1")
196196
>"readonlyProp" : "readonlyProp"
197197
>{ value: "Smith", writable: false } : { value: string; writable: false; }
@@ -202,9 +202,9 @@ Object.defineProperty(exports, "readonlyProp", { value: "Smith", writable: false
202202

203203
Object.defineProperty(exports, "rwAccessors", { get() { return 98122 }, set(_) { /*ignore*/ } });
204204
>Object.defineProperty(exports, "rwAccessors", { get() { return 98122 }, set(_) { /*ignore*/ } }) : typeof import("tests/cases/conformance/jsdoc/mod1")
205-
>Object.defineProperty : <T>(o: T, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => T
205+
>Object.defineProperty : <T extends object>(o: T, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => T
206206
>Object : ObjectConstructor
207-
>defineProperty : <T>(o: T, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => T
207+
>defineProperty : <T extends object>(o: T, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => T
208208
>exports : typeof import("tests/cases/conformance/jsdoc/mod1")
209209
>"rwAccessors" : "rwAccessors"
210210
>{ get() { return 98122 }, set(_) { /*ignore*/ } } : { get(): number; set(_: any): void; }
@@ -215,9 +215,9 @@ Object.defineProperty(exports, "rwAccessors", { get() { return 98122 }, set(_) {
215215

216216
Object.defineProperty(exports, "readonlyAccessor", { get() { return 21.75 } });
217217
>Object.defineProperty(exports, "readonlyAccessor", { get() { return 21.75 } }) : typeof import("tests/cases/conformance/jsdoc/mod1")
218-
>Object.defineProperty : <T>(o: T, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => T
218+
>Object.defineProperty : <T extends object>(o: T, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => T
219219
>Object : ObjectConstructor
220-
>defineProperty : <T>(o: T, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => T
220+
>defineProperty : <T extends object>(o: T, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => T
221221
>exports : typeof import("tests/cases/conformance/jsdoc/mod1")
222222
>"readonlyAccessor" : "readonlyAccessor"
223223
>{ get() { return 21.75 } } : { get(): number; }
@@ -226,9 +226,9 @@ Object.defineProperty(exports, "readonlyAccessor", { get() { return 21.75 } });
226226

227227
Object.defineProperty(exports, "setonlyAccessor", {
228228
>Object.defineProperty(exports, "setonlyAccessor", { /** @param {string} str */ set(str) { this.rwAccessors = Number(str) }}) : typeof import("tests/cases/conformance/jsdoc/mod1")
229-
>Object.defineProperty : <T>(o: T, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => T
229+
>Object.defineProperty : <T extends object>(o: T, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => T
230230
>Object : ObjectConstructor
231-
>defineProperty : <T>(o: T, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => T
231+
>defineProperty : <T extends object>(o: T, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => T
232232
>exports : typeof import("tests/cases/conformance/jsdoc/mod1")
233233
>"setonlyAccessor" : "setonlyAccessor"
234234
>{ /** @param {string} str */ set(str) { this.rwAccessors = Number(str) }} : { set(str: string): void; }
@@ -252,9 +252,9 @@ Object.defineProperty(exports, "setonlyAccessor", {
252252
=== tests/cases/conformance/jsdoc/mod2.js ===
253253
Object.defineProperty(module.exports, "thing", { value: "yes", writable: true });
254254
>Object.defineProperty(module.exports, "thing", { value: "yes", writable: true }) : typeof module.exports
255-
>Object.defineProperty : <T>(o: T, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => T
255+
>Object.defineProperty : <T extends object>(o: T, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => T
256256
>Object : ObjectConstructor
257-
>defineProperty : <T>(o: T, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => T
257+
>defineProperty : <T extends object>(o: T, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => T
258258
>module.exports : typeof module.exports
259259
>module : { exports: typeof module.exports; }
260260
>exports : typeof module.exports
@@ -267,9 +267,9 @@ Object.defineProperty(module.exports, "thing", { value: "yes", writable: true })
267267

268268
Object.defineProperty(module.exports, "readonlyProp", { value: "Smith", writable: false });
269269
>Object.defineProperty(module.exports, "readonlyProp", { value: "Smith", writable: false }) : typeof module.exports
270-
>Object.defineProperty : <T>(o: T, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => T
270+
>Object.defineProperty : <T extends object>(o: T, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => T
271271
>Object : ObjectConstructor
272-
>defineProperty : <T>(o: T, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => T
272+
>defineProperty : <T extends object>(o: T, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => T
273273
>module.exports : typeof module.exports
274274
>module : { exports: typeof module.exports; }
275275
>exports : typeof module.exports
@@ -282,9 +282,9 @@ Object.defineProperty(module.exports, "readonlyProp", { value: "Smith", writable
282282

283283
Object.defineProperty(module.exports, "rwAccessors", { get() { return 98122 }, set(_) { /*ignore*/ } });
284284
>Object.defineProperty(module.exports, "rwAccessors", { get() { return 98122 }, set(_) { /*ignore*/ } }) : typeof module.exports
285-
>Object.defineProperty : <T>(o: T, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => T
285+
>Object.defineProperty : <T extends object>(o: T, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => T
286286
>Object : ObjectConstructor
287-
>defineProperty : <T>(o: T, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => T
287+
>defineProperty : <T extends object>(o: T, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => T
288288
>module.exports : typeof module.exports
289289
>module : { exports: typeof module.exports; }
290290
>exports : typeof module.exports
@@ -297,9 +297,9 @@ Object.defineProperty(module.exports, "rwAccessors", { get() { return 98122 }, s
297297

298298
Object.defineProperty(module.exports, "readonlyAccessor", { get() { return 21.75 } });
299299
>Object.defineProperty(module.exports, "readonlyAccessor", { get() { return 21.75 } }) : typeof module.exports
300-
>Object.defineProperty : <T>(o: T, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => T
300+
>Object.defineProperty : <T extends object>(o: T, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => T
301301
>Object : ObjectConstructor
302-
>defineProperty : <T>(o: T, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => T
302+
>defineProperty : <T extends object>(o: T, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => T
303303
>module.exports : typeof module.exports
304304
>module : { exports: typeof module.exports; }
305305
>exports : typeof module.exports
@@ -310,9 +310,9 @@ Object.defineProperty(module.exports, "readonlyAccessor", { get() { return 21.75
310310

311311
Object.defineProperty(module.exports, "setonlyAccessor", {
312312
>Object.defineProperty(module.exports, "setonlyAccessor", { /** @param {string} str */ set(str) { this.rwAccessors = Number(str) }}) : typeof module.exports
313-
>Object.defineProperty : <T>(o: T, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => T
313+
>Object.defineProperty : <T extends object>(o: T, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => T
314314
>Object : ObjectConstructor
315-
>defineProperty : <T>(o: T, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => T
315+
>defineProperty : <T extends object>(o: T, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => T
316316
>module.exports : typeof module.exports
317317
>module : { exports: typeof module.exports; }
318318
>exports : typeof module.exports

0 commit comments

Comments
 (0)