Skip to content

Commit 4d53a21

Browse files
committed
Merge pull request #8362 from Microsoft/Fix8338
Fix #8338: add signatures to RegExp constructor accepting RegExp
2 parents a7e4046 + b6e98e5 commit 4d53a21

File tree

2 files changed

+815
-808
lines changed

2 files changed

+815
-808
lines changed

src/lib/es2015.core.d.ts

Lines changed: 67 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,46 @@
11
declare type PropertyKey = string | number | symbol;
22

33
interface Array<T> {
4-
/**
5-
* Returns the value of the first element in the array where predicate is true, and undefined
4+
/**
5+
* Returns the value of the first element in the array where predicate is true, and undefined
66
* otherwise.
7-
* @param predicate find calls predicate once for each element of the array, in ascending
8-
* order, until it finds one where predicate returns true. If such an element is found, find
7+
* @param predicate find calls predicate once for each element of the array, in ascending
8+
* order, until it finds one where predicate returns true. If such an element is found, find
99
* immediately returns that element value. Otherwise, find returns undefined.
10-
* @param thisArg If provided, it will be used as the this value for each invocation of
10+
* @param thisArg If provided, it will be used as the this value for each invocation of
1111
* predicate. If it is not provided, undefined is used instead.
1212
*/
1313
find(predicate: (value: T, index: number, obj: Array<T>) => boolean, thisArg?: any): T | undefined;
1414

15-
/**
16-
* Returns the index of the first element in the array where predicate is true, and undefined
15+
/**
16+
* Returns the index of the first element in the array where predicate is true, and undefined
1717
* otherwise.
18-
* @param predicate find calls predicate once for each element of the array, in ascending
19-
* order, until it finds one where predicate returns true. If such an element is found, find
18+
* @param predicate find calls predicate once for each element of the array, in ascending
19+
* order, until it finds one where predicate returns true. If such an element is found, find
2020
* immediately returns that element value. Otherwise, find returns undefined.
21-
* @param thisArg If provided, it will be used as the this value for each invocation of
21+
* @param thisArg If provided, it will be used as the this value for each invocation of
2222
* predicate. If it is not provided, undefined is used instead.
2323
*/
2424
findIndex(predicate: (value: T) => boolean, thisArg?: any): number | undefined;
2525

2626
/**
2727
* Returns the this object after filling the section identified by start and end with value
2828
* @param value value to fill array section with
29-
* @param start index to start filling the array at. If start is negative, it is treated as
30-
* length+start where length is the length of the array.
31-
* @param end index to stop filling the array at. If end is negative, it is treated as
29+
* @param start index to start filling the array at. If start is negative, it is treated as
30+
* length+start where length is the length of the array.
31+
* @param end index to stop filling the array at. If end is negative, it is treated as
3232
* length+end.
3333
*/
3434
fill(value: T, start?: number, end?: number): T[];
3535

36-
/**
36+
/**
3737
* Returns the this object after copying a section of the array identified by start and end
3838
* to the same array starting at position target
39-
* @param target If target is negative, it is treated as length+target where length is the
40-
* length of the array.
41-
* @param start If start is negative, it is treated as length+start. If end is negative, it
39+
* @param target If target is negative, it is treated as length+target where length is the
40+
* length of the array.
41+
* @param start If start is negative, it is treated as length+start. If end is negative, it
4242
* is treated as length+end.
43-
* @param end If not specified, length of the this object is used as its default value.
43+
* @param end If not specified, length of the this object is used as its default value.
4444
*/
4545
copyWithin(target: number, start: number, end?: number): T[];
4646
}
@@ -114,7 +114,7 @@ interface Math {
114114
log1p(x: number): number;
115115

116116
/**
117-
* Returns the result of (e^x - 1) of x (e raised to the power of x, where e is the base of
117+
* Returns the result of (e^x - 1) of x (e raised to the power of x, where e is the base of
118118
* the natural logarithms).
119119
* @param x A numeric expression.
120120
*/
@@ -190,14 +190,14 @@ interface Math {
190190
interface NumberConstructor {
191191
/**
192192
* The value of Number.EPSILON is the difference between 1 and the smallest value greater than 1
193-
* that is representable as a Number value, which is approximately:
193+
* that is representable as a Number value, which is approximately:
194194
* 2.2204460492503130808472633361816 x 10‍−‍16.
195195
*/
196196
readonly EPSILON: number;
197197

198198
/**
199199
* Returns true if passed value is finite.
200-
* Unlike the global isFininte, Number.isFinite doesn't forcibly convert the parameter to a
200+
* Unlike the global isFininte, Number.isFinite doesn't forcibly convert the parameter to a
201201
* number. Only finite values of the type number, result in true.
202202
* @param number A numeric value.
203203
*/
@@ -210,7 +210,7 @@ interface NumberConstructor {
210210
isInteger(number: number): boolean;
211211

212212
/**
213-
* Returns a Boolean value that indicates whether a value is the reserved value NaN (not a
213+
* Returns a Boolean value that indicates whether a value is the reserved value NaN (not a
214214
* number). Unlike the global isNaN(), Number.isNaN() doesn't forcefully convert the parameter
215215
* to a number. Only values of the type number, that are also NaN, result in true.
216216
* @param number A numeric value.
@@ -223,30 +223,30 @@ interface NumberConstructor {
223223
*/
224224
isSafeInteger(number: number): boolean;
225225

226-
/**
227-
* The value of the largest integer n such that n and n + 1 are both exactly representable as
228-
* a Number value.
226+
/**
227+
* The value of the largest integer n such that n and n + 1 are both exactly representable as
228+
* a Number value.
229229
* The value of Number.MIN_SAFE_INTEGER is 9007199254740991 2^53 − 1.
230230
*/
231231
readonly MAX_SAFE_INTEGER: number;
232232

233-
/**
234-
* The value of the smallest integer n such that n and n − 1 are both exactly representable as
235-
* a Number value.
233+
/**
234+
* The value of the smallest integer n such that n and n − 1 are both exactly representable as
235+
* a Number value.
236236
* The value of Number.MIN_SAFE_INTEGER is −9007199254740991 (−(2^53 − 1)).
237237
*/
238238
readonly MIN_SAFE_INTEGER: number;
239239

240240
/**
241-
* Converts a string to a floating-point number.
242-
* @param string A string that contains a floating-point number.
241+
* Converts a string to a floating-point number.
242+
* @param string A string that contains a floating-point number.
243243
*/
244244
parseFloat(string: string): number;
245245

246246
/**
247247
* Converts A string to an integer.
248248
* @param s A string to convert into a number.
249-
* @param radix A value between 2 and 36 that specifies the base of the number in numString.
249+
* @param radix A value between 2 and 36 that specifies the base of the number in numString.
250250
* If this argument is not supplied, strings with a prefix of '0x' are considered hexadecimal.
251251
* All other strings are considered decimal.
252252
*/
@@ -255,12 +255,12 @@ interface NumberConstructor {
255255

256256
interface Object {
257257
/**
258-
* Determines whether an object has a property with the specified name.
258+
* Determines whether an object has a property with the specified name.
259259
* @param v A property name.
260260
*/
261261
hasOwnProperty(v: PropertyKey): boolean
262262

263-
/**
263+
/**
264264
* Determines whether a specified property is enumerable.
265265
* @param v A property name.
266266
*/
@@ -269,15 +269,15 @@ interface Object {
269269

270270
interface ObjectConstructor {
271271
/**
272-
* Copy the values of all of the enumerable own properties from one or more source objects to a
272+
* Copy the values of all of the enumerable own properties from one or more source objects to a
273273
* target object. Returns the target object.
274274
* @param target The target object to copy to.
275275
* @param source The source object from which to copy properties.
276276
*/
277277
assign<T, U>(target: T, source: U): T & U;
278278

279279
/**
280-
* Copy the values of all of the enumerable own properties from one or more source objects to a
280+
* Copy the values of all of the enumerable own properties from one or more source objects to a
281281
* target object. Returns the target object.
282282
* @param target The target object to copy to.
283283
* @param source1 The first source object from which to copy properties.
@@ -286,7 +286,7 @@ interface ObjectConstructor {
286286
assign<T, U, V>(target: T, source1: U, source2: V): T & U & V;
287287

288288
/**
289-
* Copy the values of all of the enumerable own properties from one or more source objects to a
289+
* Copy the values of all of the enumerable own properties from one or more source objects to a
290290
* target object. Returns the target object.
291291
* @param target The target object to copy to.
292292
* @param source1 The first source object from which to copy properties.
@@ -296,7 +296,7 @@ interface ObjectConstructor {
296296
assign<T, U, V, W>(target: T, source1: U, source2: V, source3: W): T & U & V & W;
297297

298298
/**
299-
* Copy the values of all of the enumerable own properties from one or more source objects to a
299+
* Copy the values of all of the enumerable own properties from one or more source objects to a
300300
* target object. Returns the target object.
301301
* @param target The target object to copy to.
302302
* @param sources One or more source objects from which to copy properties
@@ -324,17 +324,17 @@ interface ObjectConstructor {
324324
setPrototypeOf(o: any, proto: any): any;
325325

326326
/**
327-
* Gets the own property descriptor of the specified object.
328-
* An own property descriptor is one that is defined directly on the object and is not
329-
* inherited from the object's prototype.
327+
* Gets the own property descriptor of the specified object.
328+
* An own property descriptor is one that is defined directly on the object and is not
329+
* inherited from the object's prototype.
330330
* @param o Object that contains the property.
331331
* @param p Name of the property.
332332
*/
333333
getOwnPropertyDescriptor(o: any, propertyKey: PropertyKey): PropertyDescriptor;
334334

335335
/**
336-
* Adds a property to an object, or modifies attributes of an existing property.
337-
* @param o Object on which to add or modify the property. This can be a native JavaScript
336+
* Adds a property to an object, or modifies attributes of an existing property.
337+
* @param o Object on which to add or modify the property. This can be a native JavaScript
338338
* object (that is, a user-defined object or a built in object) or a DOM object.
339339
* @param p The property name.
340340
* @param attributes Descriptor for the property. It can be for a data property or an accessor
@@ -358,63 +358,68 @@ interface RegExp {
358358
*/
359359
readonly flags: string;
360360

361-
/**
362-
* Returns a Boolean value indicating the state of the sticky flag (y) used with a regular
363-
* expression. Default is false. Read-only.
361+
/**
362+
* Returns a Boolean value indicating the state of the sticky flag (y) used with a regular
363+
* expression. Default is false. Read-only.
364364
*/
365365
readonly sticky: boolean;
366366

367-
/**
368-
* Returns a Boolean value indicating the state of the Unicode flag (u) used with a regular
369-
* expression. Default is false. Read-only.
367+
/**
368+
* Returns a Boolean value indicating the state of the Unicode flag (u) used with a regular
369+
* expression. Default is false. Read-only.
370370
*/
371371
readonly unicode: boolean;
372372
}
373373

374+
interface RegExpConstructor {
375+
new (pattern: RegExp, flags?: string): RegExp;
376+
(pattern: RegExp, flags?: string): RegExp;
377+
}
378+
374379
interface String {
375380
/**
376-
* Returns a nonnegative integer Number less than 1114112 (0x110000) that is the code point
377-
* value of the UTF-16 encoded code point starting at the string element at position pos in
378-
* the String resulting from converting this object to a String.
379-
* If there is no element at that position, the result is undefined.
381+
* Returns a nonnegative integer Number less than 1114112 (0x110000) that is the code point
382+
* value of the UTF-16 encoded code point starting at the string element at position pos in
383+
* the String resulting from converting this object to a String.
384+
* If there is no element at that position, the result is undefined.
380385
* If a valid UTF-16 surrogate pair does not begin at pos, the result is the code unit at pos.
381386
*/
382387
codePointAt(pos: number): number | undefined;
383388

384389
/**
385-
* Returns true if searchString appears as a substring of the result of converting this
386-
* object to a String, at one or more positions that are
390+
* Returns true if searchString appears as a substring of the result of converting this
391+
* object to a String, at one or more positions that are
387392
* greater than or equal to position; otherwise, returns false.
388-
* @param searchString search string
393+
* @param searchString search string
389394
* @param position If position is undefined, 0 is assumed, so as to search all of the String.
390395
*/
391396
includes(searchString: string, position?: number): boolean;
392397

393398
/**
394-
* Returns true if the sequence of elements of searchString converted to a String is the
395-
* same as the corresponding elements of this object (converted to a String) starting at
399+
* Returns true if the sequence of elements of searchString converted to a String is the
400+
* same as the corresponding elements of this object (converted to a String) starting at
396401
* endPosition – length(this). Otherwise returns false.
397402
*/
398403
endsWith(searchString: string, endPosition?: number): boolean;
399404

400405
/**
401-
* Returns the String value result of normalizing the string into the normalization form
406+
* Returns the String value result of normalizing the string into the normalization form
402407
* named by form as specified in Unicode Standard Annex #15, Unicode Normalization Forms.
403408
* @param form Applicable values: "NFC", "NFD", "NFKC", or "NFKD", If not specified default
404409
* is "NFC"
405410
*/
406411
normalize(form?: string): string;
407412

408413
/**
409-
* Returns a String value that is made from count copies appended together. If count is 0,
414+
* Returns a String value that is made from count copies appended together. If count is 0,
410415
* T is the empty String is returned.
411416
* @param count number of copies to append
412417
*/
413418
repeat(count: number): string;
414419

415420
/**
416-
* Returns true if the sequence of elements of searchString converted to a String is the
417-
* same as the corresponding elements of this object (converted to a String) starting at
421+
* Returns true if the sequence of elements of searchString converted to a String is the
422+
* same as the corresponding elements of this object (converted to a String) starting at
418423
* position. Otherwise returns false.
419424
*/
420425
startsWith(searchString: string, position?: number): boolean;
@@ -474,7 +479,7 @@ interface StringConstructor {
474479

475480
/**
476481
* String.raw is intended for use as a tag function of a Tagged Template String. When called
477-
* as such the first argument will be a well formed template call site object and the rest
482+
* as such the first argument will be a well formed template call site object and the rest
478483
* parameter will contain the substitution values.
479484
* @param template A well-formed template string call site representation.
480485
* @param substitutions A set of substitution values.

0 commit comments

Comments
 (0)