Skip to content

Commit 32512b6

Browse files
committed
fix: fix for ES2021 libs
1 parent 4e4f7d8 commit 32512b6

File tree

7 files changed

+44
-34
lines changed

7 files changed

+44
-34
lines changed

build/replacement.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,6 @@ export const replacement = new Map([
4545
["es2018.asyncgenerator.d.ts", new Set(["AsyncGenerator"])],
4646
["es2018.asynciterable.d.ts", new Set(["AsyncIterator"])],
4747
["es2019.object.d.ts", new Set(["ObjectConstructor"])],
48-
["esnext.promise.d.ts", new Set(["AggregateError"])],
49-
["esnext.string.d.ts", new Set(["String"])],
48+
["es2021.promise.d.ts", new Set(["AggregateError"])],
49+
["es2021.string.d.ts", new Set(["String"])],
5050
]);

generated/lib.es2021.promise.d.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
1-
interface AggregateError extends Error {
2-
errors: any[]
3-
}
1+
/// <reference path="./better/lib.es2021.promise.d.ts" />
2+
3+
// interface AggregateError extends Error {
4+
// errors: any[]
5+
// }
6+
47

58
interface AggregateErrorConstructor {
69
new(errors: Iterable<any>, message?: string): AggregateError;
710
(errors: Iterable<any>, message?: string): AggregateError;
811
readonly prototype: AggregateError;
9-
}
12+
}
13+
//
14+
//
15+
// declare var AggregateError: AggregateErrorConstructor;
1016

11-
declare var AggregateError: AggregateErrorConstructor;
1217

1318
/**
1419
* Represents the completion of an asynchronous operation

generated/lib.es2021.string.d.ts

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
1-
interface String {
2-
/**
3-
* Replace all instances of a substring in a string, using a regular expression or search string.
4-
* @param searchValue A string to search for.
5-
* @param replaceValue A string containing the text to replace for every successful match of searchValue in this string.
6-
*/
7-
replaceAll(searchValue: string | RegExp, replaceValue: string): string;
1+
/// <reference path="./better/lib.es2021.string.d.ts" />
2+
3+
// interface String {
4+
// /**
5+
// * Replace all instances of a substring in a string, using a regular expression or search string.
6+
// * @param searchValue A string to search for.
7+
// * @param replaceValue A string containing the text to replace for every successful match of searchValue in this string.
8+
// */
9+
// replaceAll(searchValue: string | RegExp, replaceValue: string): string;
10+
//
11+
// /**
12+
// * Replace all instances of a substring in a string, using a regular expression or search string.
13+
// * @param searchValue A string to search for.
14+
// * @param replacer A function that returns the replacement text.
15+
// */
16+
// replaceAll(searchValue: string | RegExp, replacer: (substring: string, ...args: any[]) => string): string;
17+
// }
818

9-
/**
10-
* Replace all instances of a substring in a string, using a regular expression or search string.
11-
* @param searchValue A string to search for.
12-
* @param replacer A function that returns the replacement text.
13-
*/
14-
replaceAll(searchValue: string | RegExp, replacer: (substring: string, ...args: any[]) => string): string;
15-
}
File renamed without changes.

lib/lib.esnext.string.d.ts renamed to lib/lib.es2021.string.d.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ interface String {
1515
*/
1616
replaceAll(
1717
searchValue: string | RegExp,
18-
// TODO: possible improvement in TS4.2
19-
replacer: (substring: string, ...args: (string | number)[]) => string
18+
replacer: (
19+
substring: string,
20+
// TODO: could be improved, but blocked by issue:
21+
// https://github.com/microsoft/TypeScript/issues/45972
22+
...rest: (string | number)[]
23+
) => string
2024
): string;
2125
}

tests/es2021.string.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/// <reference path="../generated/lib.es2021.d.ts" />
2+
3+
// String
4+
"foobar".replaceAll(/foo/g, (substr, p1, p2) => {
5+
// expectType<string>(substr);
6+
// expectType<string | number>(p1);
7+
// expectType<string | number>(p2);
8+
return "";
9+
});

tests/esnext.string.ts

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)