Skip to content

Commit 732ece6

Browse files
committed
feat: upgrade TypeScript to 5.0
2 parents 5cc0b10 + 49350f2 commit 732ece6

File tree

96 files changed

+5345
-4913
lines changed

Some content is hidden

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

96 files changed

+5345
-4913
lines changed

TypeScript

Submodule TypeScript updated 7937 files

build/diff.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ async function main() {
2323
const libFiles = await getLibFiles();
2424
const hasDiffFiles: string[] = [];
2525
for (const [targetFile, sourceFile] of libFiles.entries()) {
26-
const betterLib = generate(tsLibDir, targetFile, sourceFile, false);
26+
const betterLib = generate(tsLibDir, targetFile, sourceFile, {
27+
emitOriginalAsComment: false,
28+
emitNoDefaultLib: false,
29+
});
2730
if (betterLib === undefined) {
2831
continue;
2932
}

build/lib.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ async function main() {
2121

2222
// modify each lib file
2323
for (const [targetFile, sourceFile] of libFiles.entries()) {
24-
let result = generate(tsLibDir, targetFile, sourceFile, true);
24+
let result = generate(tsLibDir, targetFile, sourceFile, {
25+
emitOriginalAsComment: true,
26+
emitNoDefaultLib: true,
27+
});
2528
if (result === undefined) {
2629
continue;
2730
}

build/logic/generate.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,19 @@ import { projectDir } from "./projectDir";
66

77
const betterLibDir = path.join(projectDir, "lib");
88

9+
type GenerateOptions = {
10+
emitOriginalAsComment?: boolean;
11+
emitNoDefaultLib?: boolean;
12+
};
13+
914
/**
1015
* Generate one better lib file.
1116
*/
1217
export function generate(
1318
tsLibDir: string,
1419
targetFile: string,
1520
sourceFile: string,
16-
emitOriginalAsComment: boolean
21+
{ emitOriginalAsComment = false, emitNoDefaultLib = false }: GenerateOptions
1722
): string | undefined {
1823
const tsLibFile = path.join(tsLibDir, sourceFile);
1924
const originalProgram = ts.createProgram([tsLibFile], {});
@@ -24,9 +29,11 @@ export function generate(
2429

2530
const printer = ts.createPrinter();
2631

27-
// This is used as a good indicator of being a default lib file
28-
let result = `/// <reference no-default-lib="true"/>
29-
`;
32+
let result = emitNoDefaultLib
33+
? // This is used as a good indicator of being a default lib file
34+
`/// <reference no-default-lib="true"/>
35+
`
36+
: "";
3037

3138
const replacementTargets = scanBetterFile(printer, targetFile);
3239

@@ -332,10 +339,10 @@ function printInterface(
332339
let result = originalNode
333340
.getFullText(originalSourceFile)
334341
.slice(0, originalNode.getLeadingTriviaWidth(originalSourceFile));
335-
for (const dec of originalNode.decorators ?? []) {
342+
for (const mod of originalNode.modifiers ?? []) {
336343
result += printer.printNode(
337344
ts.EmitHint.Unspecified,
338-
dec,
345+
mod,
339346
originalSourceFile
340347
);
341348
}
@@ -414,7 +421,7 @@ function replaceAliases(
414421
}
415422
return ts.visitEachChild(node, visitor, context);
416423
};
417-
return ts.visitNode(sourceStatement, visitor);
424+
return ts.visitNode(sourceStatement, visitor, ts.isStatement);
418425
},
419426
]).transformed[0];
420427
}

docs/diff.md

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -4,72 +4,20 @@
44
The following files are improved in better-typescript-lib:
55

66
- [es5.d.ts](./diff/es5.d.ts.md)
7-
- [es2015.d.ts](./diff/es2015.d.ts.md)
8-
- [es2016.d.ts](./diff/es2016.d.ts.md)
9-
- [es2017.d.ts](./diff/es2017.d.ts.md)
10-
- [es2018.d.ts](./diff/es2018.d.ts.md)
11-
- [es2019.d.ts](./diff/es2019.d.ts.md)
12-
- [es2020.d.ts](./diff/es2020.d.ts.md)
13-
- [es2021.d.ts](./diff/es2021.d.ts.md)
14-
- [es2022.d.ts](./diff/es2022.d.ts.md)
15-
- [esnext.d.ts](./diff/esnext.d.ts.md)
167
- [dom.generated.d.ts](./diff/dom.generated.d.ts.md)
17-
- [dom.iterable.generated.d.ts](./diff/dom.iterable.generated.d.ts.md)
18-
- [webworker.generated.d.ts](./diff/webworker.generated.d.ts.md)
19-
- [webworker.importscripts.d.ts](./diff/webworker.importscripts.d.ts.md)
20-
- [webworker.iterable.generated.d.ts](./diff/webworker.iterable.generated.d.ts.md)
21-
- [scripthost.d.ts](./diff/scripthost.d.ts.md)
228
- [es2015.core.d.ts](./diff/es2015.core.d.ts.md)
239
- [es2015.collection.d.ts](./diff/es2015.collection.d.ts.md)
2410
- [es2015.generator.d.ts](./diff/es2015.generator.d.ts.md)
2511
- [es2015.iterable.d.ts](./diff/es2015.iterable.d.ts.md)
2612
- [es2015.promise.d.ts](./diff/es2015.promise.d.ts.md)
2713
- [es2015.proxy.d.ts](./diff/es2015.proxy.d.ts.md)
2814
- [es2015.reflect.d.ts](./diff/es2015.reflect.d.ts.md)
29-
- [es2015.symbol.d.ts](./diff/es2015.symbol.d.ts.md)
3015
- [es2015.symbol.wellknown.d.ts](./diff/es2015.symbol.wellknown.d.ts.md)
31-
- [es2016.array.include.d.ts](./diff/es2016.array.include.d.ts.md)
3216
- [es2017.object.d.ts](./diff/es2017.object.d.ts.md)
33-
- [es2017.sharedmemory.d.ts](./diff/es2017.sharedmemory.d.ts.md)
34-
- [es2017.string.d.ts](./diff/es2017.string.d.ts.md)
35-
- [es2017.intl.d.ts](./diff/es2017.intl.d.ts.md)
36-
- [es2017.typedarrays.d.ts](./diff/es2017.typedarrays.d.ts.md)
3717
- [es2018.asyncgenerator.d.ts](./diff/es2018.asyncgenerator.d.ts.md)
3818
- [es2018.asynciterable.d.ts](./diff/es2018.asynciterable.d.ts.md)
39-
- [es2018.regexp.d.ts](./diff/es2018.regexp.d.ts.md)
40-
- [es2018.promise.d.ts](./diff/es2018.promise.d.ts.md)
41-
- [es2018.intl.d.ts](./diff/es2018.intl.d.ts.md)
42-
- [es2019.array.d.ts](./diff/es2019.array.d.ts.md)
4319
- [es2019.object.d.ts](./diff/es2019.object.d.ts.md)
44-
- [es2019.string.d.ts](./diff/es2019.string.d.ts.md)
45-
- [es2019.symbol.d.ts](./diff/es2019.symbol.d.ts.md)
46-
- [es2019.intl.d.ts](./diff/es2019.intl.d.ts.md)
4720
- [es2020.bigint.d.ts](./diff/es2020.bigint.d.ts.md)
48-
- [es2020.date.d.ts](./diff/es2020.date.d.ts.md)
49-
- [es2020.promise.d.ts](./diff/es2020.promise.d.ts.md)
50-
- [es2020.sharedmemory.d.ts](./diff/es2020.sharedmemory.d.ts.md)
51-
- [es2020.string.d.ts](./diff/es2020.string.d.ts.md)
52-
- [es2020.symbol.wellknown.d.ts](./diff/es2020.symbol.wellknown.d.ts.md)
53-
- [es2020.intl.d.ts](./diff/es2020.intl.d.ts.md)
54-
- [es2020.number.d.ts](./diff/es2020.number.d.ts.md)
5521
- [es2021.string.d.ts](./diff/es2021.string.d.ts.md)
5622
- [es2021.promise.d.ts](./diff/es2021.promise.d.ts.md)
57-
- [es2021.weakref.d.ts](./diff/es2021.weakref.d.ts.md)
58-
- [es2021.intl.d.ts](./diff/es2021.intl.d.ts.md)
59-
- [es2022.array.d.ts](./diff/es2022.array.d.ts.md)
60-
- [es2022.error.d.ts](./diff/es2022.error.d.ts.md)
61-
- [es2022.intl.d.ts](./diff/es2022.intl.d.ts.md)
6223
- [es2022.object.d.ts](./diff/es2022.object.d.ts.md)
63-
- [es2022.sharedmemory.d.ts](./diff/es2022.sharedmemory.d.ts.md)
64-
- [es2022.string.d.ts](./diff/es2022.string.d.ts.md)
65-
- [esnext.intl.d.ts](./diff/esnext.intl.d.ts.md)
66-
- [es5.full.d.ts](./diff/es5.full.d.ts.md)
67-
- [es2015.full.d.ts](./diff/es2015.full.d.ts.md)
68-
- [es2016.full.d.ts](./diff/es2016.full.d.ts.md)
69-
- [es2017.full.d.ts](./diff/es2017.full.d.ts.md)
70-
- [es2018.full.d.ts](./diff/es2018.full.d.ts.md)
71-
- [es2019.full.d.ts](./diff/es2019.full.d.ts.md)
72-
- [es2020.full.d.ts](./diff/es2020.full.d.ts.md)
73-
- [es2021.full.d.ts](./diff/es2021.full.d.ts.md)
74-
- [es2022.full.d.ts](./diff/es2022.full.d.ts.md)
75-
- [esnext.full.d.ts](./diff/esnext.full.d.ts.md)

docs/diff/dom.generated.d.ts.md

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,7 @@ Index: dom.generated.d.ts
55
===================================================================
66
--- dom.generated.d.ts
77
+++ dom.generated.d.ts
8-
@@ -1,4 +1,5 @@
9-
+/// <reference no-default-lib="true"/>
10-
/////////////////////////////
11-
/// Window APIs
12-
/////////////////////////////
13-
14-
@@ -2800,9 +2801,9 @@
8+
@@ -2821,9 +2821,9 @@
159
readonly bodyUsed: boolean;
1610
arrayBuffer(): Promise<ArrayBuffer>;
1711
blob(): Promise<Blob>;

docs/diff/dom.iterable.generated.d.ts.md

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

docs/diff/es2015.collection.d.ts.md

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,7 @@ Index: es2015.collection.d.ts
55
===================================================================
66
--- es2015.collection.d.ts
77
+++ es2015.collection.d.ts
8-
@@ -1,4 +1,5 @@
9-
+/// <reference no-default-lib="true"/>
10-
interface Map<K, V> {
11-
clear(): void;
12-
/**
13-
* @returns true if an element in the Map existed and has been removed, or false if the element does not exist.
14-
@@ -6,11 +7,11 @@
8+
@@ -6,11 +6,11 @@
159
delete(key: K): boolean;
1610
/**
1711
* Executes a provided function once per each key/value pair in the Map, in insertion order.
@@ -26,7 +20,7 @@ Index: es2015.collection.d.ts
2620
/**
2721
* Returns a specified element from the Map object. If the value that is associated to the provided key is an object, then you will get a reference to that object and any change made to that object will effectively modify it inside the Map.
2822
* @returns Returns the element associated with the specified key. If no element is associated with the specified key, undefined is returned.
29-
@@ -30,18 +31,17 @@
23+
@@ -30,18 +30,17 @@
3024
readonly size: number;
3125
}
3226

@@ -49,7 +43,7 @@ Index: es2015.collection.d.ts
4943
get(key: K): V | undefined;
5044
has(key: K): boolean;
5145
readonly size: number;
52-
@@ -68,12 +68,12 @@
46+
@@ -68,12 +67,12 @@
5347
set(key: K, value: V): this;
5448
}
5549

@@ -65,7 +59,7 @@ Index: es2015.collection.d.ts
6559
declare var WeakMap: WeakMapConstructor;
6660

6761
interface Set<T> {
68-
@@ -90,11 +90,11 @@
62+
@@ -90,11 +89,11 @@
6963
delete(value: T): boolean;
7064
/**
7165
* Executes a provided function once per each value in the Set object, in insertion order.
@@ -80,7 +74,7 @@ Index: es2015.collection.d.ts
8074
/**
8175
* @returns a boolean indicating whether an element with the specified value exists in the Set or not.
8276
*/
83-
@@ -105,17 +105,17 @@
77+
@@ -105,17 +104,17 @@
8478
readonly size: number;
8579
}
8680

docs/diff/es2015.core.d.ts.md

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,13 @@ Index: es2015.core.d.ts
55
===================================================================
66
--- es2015.core.d.ts
77
+++ es2015.core.d.ts
8-
@@ -1,4 +1,5 @@
9-
+/// <reference no-default-lib="true"/>
10-
interface Array<T> {
11-
/**
12-
* Returns the value of the first element in the array where predicate is true, and undefined
13-
* otherwise.
14-
@@ -7,15 +8,25 @@
8+
@@ -7,15 +7,25 @@
159
* immediately returns that element value. Otherwise, find returns undefined.
1610
* @param thisArg If provided, it will be used as the this value for each invocation of
1711
* predicate. If it is not provided, undefined is used instead.
1812
*/
1913
- find<S extends T>(
20-
- predicate: (this: void, value: T, index: number, obj: T[]) => value is S,
14+
- predicate: (value: T, index: number, obj: T[]) => value is S,
2115
- thisArg?: any
2216
+ find<S extends T, This = undefined>(
2317
+ predicate: (this: This, value: T, index: number, obj: this) => value is S,
@@ -43,7 +37,7 @@ Index: es2015.core.d.ts
4337

4438
/**
4539
* Returns the index of the first element in the array where predicate is true, and -1
46-
@@ -25,11 +36,11 @@
40+
@@ -25,11 +35,11 @@
4741
* findIndex immediately returns that element index. Otherwise, findIndex returns -1.
4842
* @param thisArg If provided, it will be used as the this value for each invocation of
4943
* predicate. If it is not provided, undefined is used instead.
@@ -58,7 +52,7 @@ Index: es2015.core.d.ts
5852

5953
/**
6054
* Changes all array elements from `start` to `end` index to a static `value` and returns the modified array
61-
@@ -54,23 +65,23 @@
55+
@@ -54,23 +64,23 @@
6256
}
6357

6458
interface ArrayConstructor {
@@ -91,7 +85,7 @@ Index: es2015.core.d.ts
9185

9286
/**
9387
* Returns a new array from a set of elements.
94-
@@ -273,49 +284,20 @@
88+
@@ -273,49 +283,20 @@
9589
/**
9690
* Copy the values of all of the enumerable own properties from one or more source objects to a
9791
* target object. Returns the target object.
@@ -146,7 +140,7 @@ Index: es2015.core.d.ts
146140
/**
147141
* Returns the names of the enumerable string properties and methods of an object.
148142
* @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.
149-
@@ -326,16 +308,23 @@
143+
@@ -326,16 +307,23 @@
150144
* Returns true if the values are the same value, false otherwise.
151145
* @param value1 The first value.
152146
* @param value2 The second value.
@@ -172,18 +166,13 @@ Index: es2015.core.d.ts
172166

173167
interface ReadonlyArray<T> {
174168
/**
175-
@@ -346,20 +335,25 @@
169+
@@ -346,15 +334,25 @@
176170
* immediately returns that element value. Otherwise, find returns undefined.
177171
* @param thisArg If provided, it will be used as the this value for each invocation of
178172
* predicate. If it is not provided, undefined is used instead.
179173
*/
180174
- find<S extends T>(
181-
- predicate: (
182-
- this: void,
183-
- value: T,
184-
- index: number,
185-
- obj: readonly T[]
186-
- ) => value is S,
175+
- predicate: (value: T, index: number, obj: readonly T[]) => value is S,
187176
- thisArg?: any
188177
+ find<S extends T, This = undefined>(
189178
+ predicate: (this: This, value: T, index: number, obj: this) => value is S,
@@ -209,7 +198,7 @@ Index: es2015.core.d.ts
209198

210199
/**
211200
* Returns the index of the first element in the array where predicate is true, and -1
212-
@@ -369,11 +363,11 @@
201+
@@ -364,11 +362,11 @@
213202
* findIndex immediately returns that element index. Otherwise, findIndex returns -1.
214203
* @param thisArg If provided, it will be used as the this value for each invocation of
215204
* predicate. If it is not provided, undefined is used instead.
@@ -224,7 +213,7 @@ Index: es2015.core.d.ts
224213
}
225214

226215
interface RegExp {
227-
@@ -433,26 +427,17 @@
216+
@@ -428,26 +426,17 @@
228217
* same as the corresponding elements of this object (converted to a String) starting at
229218
* endPosition – length(this). Otherwise returns false.
230219
*/

docs/diff/es2015.d.ts.md

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

docs/diff/es2015.full.d.ts.md

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

docs/diff/es2015.generator.d.ts.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ Index: es2015.generator.d.ts
55
===================================================================
66
--- es2015.generator.d.ts
77
+++ es2015.generator.d.ts
8-
@@ -1,7 +1,8 @@
9-
+/// <reference no-default-lib="true"/>
8+
@@ -1,7 +1,7 @@
109
/// <reference lib="es2015.iterable" />
1110

1211
-interface Generator<T = unknown, TReturn = any, TNext = unknown>

0 commit comments

Comments
 (0)