Skip to content

Commit 17b01bc

Browse files
saschanazorta
authored andcommitted
Add target: "es2022" (microsoft#46291)
* Add `target: "es2022"` * Add Object.hasOwn * formatToParts is es2018 * ref update * optional parameter * Revert "optional parameter" This reverts commit e67d6e5. * undefined * error cause * Lint fix Co-authored-by: Orta <[email protected]>
1 parent a628e68 commit 17b01bc

File tree

57 files changed

+973
-47
lines changed

Some content is hidden

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

57 files changed

+973
-47
lines changed

Diff for: src/compiler/commandLineParser.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ namespace ts {
2929
["es2019", "lib.es2019.d.ts"],
3030
["es2020", "lib.es2020.d.ts"],
3131
["es2021", "lib.es2021.d.ts"],
32+
["es2022", "lib.es2022.d.ts"],
3233
["esnext", "lib.esnext.d.ts"],
3334
// Host only
3435
["dom", "lib.dom.d.ts"],
@@ -72,12 +73,16 @@ namespace ts {
7273
["es2021.string", "lib.es2021.string.d.ts"],
7374
["es2021.weakref", "lib.es2021.weakref.d.ts"],
7475
["es2021.intl", "lib.es2021.intl.d.ts"],
75-
["esnext.array", "lib.es2019.array.d.ts"],
76+
["es2022.array", "lib.es2022.array.d.ts"],
77+
["es2022.error", "lib.es2022.error.d.ts"],
78+
["es2022.object", "lib.es2022.object.d.ts"],
79+
["es2022.string", "lib.es2022.string.d.ts"],
80+
["esnext.array", "lib.es2022.array.d.ts"],
7681
["esnext.symbol", "lib.es2019.symbol.d.ts"],
7782
["esnext.asynciterable", "lib.es2018.asynciterable.d.ts"],
7883
["esnext.intl", "lib.esnext.intl.d.ts"],
7984
["esnext.bigint", "lib.es2020.bigint.d.ts"],
80-
["esnext.string", "lib.es2021.string.d.ts"],
85+
["esnext.string", "lib.es2022.string.d.ts"],
8186
["esnext.promise", "lib.es2021.promise.d.ts"],
8287
["esnext.weakref", "lib.es2021.weakref.d.ts"]
8388
];
@@ -314,6 +319,7 @@ namespace ts {
314319
es2019: ScriptTarget.ES2019,
315320
es2020: ScriptTarget.ES2020,
316321
es2021: ScriptTarget.ES2021,
322+
es2022: ScriptTarget.ES2022,
317323
esnext: ScriptTarget.ESNext,
318324
})),
319325
affectsSourceFile: true,

Diff for: src/compiler/types.ts

+12-9
Original file line numberDiff line numberDiff line change
@@ -6268,6 +6268,7 @@ namespace ts {
62686268
ES2019 = 6,
62696269
ES2020 = 7,
62706270
ES2021 = 8,
6271+
ES2022 = 9,
62716272
ESNext = 99,
62726273
JSON = 100,
62736274
Latest = ESNext,
@@ -6725,15 +6726,16 @@ namespace ts {
67256726
ContainsTypeScript = 1 << 0,
67266727
ContainsJsx = 1 << 1,
67276728
ContainsESNext = 1 << 2,
6728-
ContainsES2021 = 1 << 3,
6729-
ContainsES2020 = 1 << 4,
6730-
ContainsES2019 = 1 << 5,
6731-
ContainsES2018 = 1 << 6,
6732-
ContainsES2017 = 1 << 7,
6733-
ContainsES2016 = 1 << 8,
6734-
ContainsES2015 = 1 << 9,
6735-
ContainsGenerator = 1 << 10,
6736-
ContainsDestructuringAssignment = 1 << 11,
6729+
ContainsES2022 = 1 << 3,
6730+
ContainsES2021 = 1 << 4,
6731+
ContainsES2020 = 1 << 5,
6732+
ContainsES2019 = 1 << 6,
6733+
ContainsES2018 = 1 << 7,
6734+
ContainsES2017 = 1 << 8,
6735+
ContainsES2016 = 1 << 9,
6736+
ContainsES2015 = 1 << 10,
6737+
ContainsGenerator = 1 << 11,
6738+
ContainsDestructuringAssignment = 1 << 12,
67376739

67386740
// Markers
67396741
// - Flags used to indicate that a subtree contains a specific transformation.
@@ -6762,6 +6764,7 @@ namespace ts {
67626764
AssertTypeScript = ContainsTypeScript,
67636765
AssertJsx = ContainsJsx,
67646766
AssertESNext = ContainsESNext,
6767+
AssertES2022 = ContainsES2022,
67656768
AssertES2021 = ContainsES2021,
67666769
AssertES2020 = ContainsES2020,
67676770
AssertES2019 = ContainsES2019,

Diff for: src/compiler/utilities.ts

+16-2
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,7 @@ namespace ts {
606606
AsyncIterableIterator: emptyArray,
607607
AsyncGenerator: emptyArray,
608608
AsyncGeneratorFunction: emptyArray,
609+
NumberFormat: ["formatToParts"]
609610
},
610611
es2019: {
611612
Array: ["flat", "flatMap"],
@@ -627,8 +628,21 @@ namespace ts {
627628
PromiseConstructor: ["any"],
628629
String: ["replaceAll"]
629630
},
630-
esnext: {
631-
NumberFormat: ["formatToParts"]
631+
es2022: {
632+
Array: ["at"],
633+
String: ["at"],
634+
Int8Array: ["at"],
635+
Uint8Array: ["at"],
636+
Uint8ClampedArray: ["at"],
637+
Int16Array: ["at"],
638+
Uint16Array: ["at"],
639+
Int32Array: ["at"],
640+
Uint32Array: ["at"],
641+
Float32Array: ["at"],
642+
Float64Array: ["at"],
643+
BigInt64Array: ["at"],
644+
BigUint64Array: ["at"],
645+
ObjectConstructor: ["hasOwn"]
632646
}
633647
};
634648
}

Diff for: src/compiler/utilitiesPublic.ts

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ namespace ts {
1414
switch (getEmitScriptTarget(options)) {
1515
case ScriptTarget.ESNext:
1616
return "lib.esnext.full.d.ts";
17+
case ScriptTarget.ES2022:
18+
return "lib.es2022.full.d.ts";
1719
case ScriptTarget.ES2021:
1820
return "lib.es2021.full.d.ts";
1921
case ScriptTarget.ES2020:

Diff for: src/lib/es2022.array.d.ts

+103
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
interface Array<T> {
2+
/**
3+
* Returns the item located at the specified index.
4+
* @param index The zero-based index of the desired code unit. A negative index will count back from the last item.
5+
*/
6+
at(index: number): T | undefined;
7+
}
8+
9+
interface ReadonlyArray<T> {
10+
/**
11+
* Returns the item located at the specified index.
12+
* @param index The zero-based index of the desired code unit. A negative index will count back from the last item.
13+
*/
14+
at(index: number): T | undefined;
15+
}
16+
17+
interface Int8Array {
18+
/**
19+
* Returns the item located at the specified index.
20+
* @param index The zero-based index of the desired code unit. A negative index will count back from the last item.
21+
*/
22+
at(index: number): number | undefined;
23+
}
24+
25+
interface Uint8Array {
26+
/**
27+
* Returns the item located at the specified index.
28+
* @param index The zero-based index of the desired code unit. A negative index will count back from the last item.
29+
*/
30+
at(index: number): number | undefined;
31+
}
32+
33+
interface Uint8ClampedArray {
34+
/**
35+
* Returns the item located at the specified index.
36+
* @param index The zero-based index of the desired code unit. A negative index will count back from the last item.
37+
*/
38+
at(index: number): number | undefined;
39+
}
40+
41+
interface Int16Array {
42+
/**
43+
* Returns the item located at the specified index.
44+
* @param index The zero-based index of the desired code unit. A negative index will count back from the last item.
45+
*/
46+
at(index: number): number | undefined;
47+
}
48+
49+
interface Uint16Array {
50+
/**
51+
* Returns the item located at the specified index.
52+
* @param index The zero-based index of the desired code unit. A negative index will count back from the last item.
53+
*/
54+
at(index: number): number | undefined;
55+
}
56+
57+
interface Int32Array {
58+
/**
59+
* Returns the item located at the specified index.
60+
* @param index The zero-based index of the desired code unit. A negative index will count back from the last item.
61+
*/
62+
at(index: number): number | undefined;
63+
}
64+
65+
interface Uint32Array {
66+
/**
67+
* Returns the item located at the specified index.
68+
* @param index The zero-based index of the desired code unit. A negative index will count back from the last item.
69+
*/
70+
at(index: number): number | undefined;
71+
}
72+
73+
interface Float32Array {
74+
/**
75+
* Returns the item located at the specified index.
76+
* @param index The zero-based index of the desired code unit. A negative index will count back from the last item.
77+
*/
78+
at(index: number): number | undefined;
79+
}
80+
81+
interface Float64Array {
82+
/**
83+
* Returns the item located at the specified index.
84+
* @param index The zero-based index of the desired code unit. A negative index will count back from the last item.
85+
*/
86+
at(index: number): number | undefined;
87+
}
88+
89+
interface BigInt64Array {
90+
/**
91+
* Returns the item located at the specified index.
92+
* @param index The zero-based index of the desired code unit. A negative index will count back from the last item.
93+
*/
94+
at(index: number): number | undefined;
95+
}
96+
97+
interface BigUint64Array {
98+
/**
99+
* Returns the item located at the specified index.
100+
* @param index The zero-based index of the desired code unit. A negative index will count back from the last item.
101+
*/
102+
at(index: number): number | undefined;
103+
}

Diff for: src/lib/es2022.d.ts

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/// <reference lib="es2021" />
2+
/// <reference lib="es2022.array" />
3+
/// <reference lib="es2022.error" />
4+
/// <reference lib="es2022.object" />
5+
/// <reference lib="es2022.string" />

Diff for: src/lib/es2022.error.d.ts

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
interface ErrorOptions {
2+
cause?: Error;
3+
}
4+
5+
interface ErrorConstructor {
6+
new(message?: string, options?: ErrorOptions): Error;
7+
(message?: string, options?: ErrorOptions): Error;
8+
}

Diff for: src/lib/es2022.full.d.ts

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/// <reference lib="es2022" />
2+
/// <reference lib="dom" />
3+
/// <reference lib="webworker.importscripts" />
4+
/// <reference lib="scripthost" />
5+
/// <reference lib="dom.iterable" />

Diff for: src/lib/es2022.object.d.ts

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
interface Object {
2+
/**
3+
* Determines whether an object has a property with the specified name.
4+
* @param o An object.
5+
* @param v A property name.
6+
*/
7+
hasOwn(o: object, v: PropertyKey): boolean;
8+
}

Diff for: src/lib/es2022.string.d.ts

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
interface String {
2+
/**
3+
* Returns a new String consisting of the single UTF-16 code unit located at the specified index.
4+
* @param index The zero-based index of the desired code unit. A negative index will count back from the last item.
5+
*/
6+
at(index: number): string | undefined;
7+
}

Diff for: src/lib/esnext.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
/// <reference lib="es2021" />
1+
/// <reference lib="es2022" />
22
/// <reference lib="esnext.intl" />

Diff for: src/lib/libs.json

+6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"es2019",
1010
"es2020",
1111
"es2021",
12+
"es2022",
1213
"esnext",
1314
// Host only
1415
"dom.generated",
@@ -52,6 +53,10 @@
5253
"es2021.promise",
5354
"es2021.weakref",
5455
"es2021.intl",
56+
"es2022.array",
57+
"es2022.error",
58+
"es2022.object",
59+
"es2022.string",
5560
"esnext.intl",
5661
// Default libraries
5762
"es5.full",
@@ -62,6 +67,7 @@
6267
"es2019.full",
6368
"es2020.full",
6469
"es2021.full",
70+
"es2022.full",
6571
"esnext.full"
6672
],
6773
"paths": {

Diff for: src/server/protocol.ts

+1
Original file line numberDiff line numberDiff line change
@@ -3534,6 +3534,7 @@ namespace ts.server.protocol {
35343534
ES2019 = "ES2019",
35353535
ES2020 = "ES2020",
35363536
ES2021 = "ES2021",
3537+
ES2022 = "ES2022",
35373538
ESNext = "ESNext"
35383539
}
35393540

Diff for: src/testRunner/unittests/config/commandLineParsing.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ namespace ts {
211211
start: undefined,
212212
length: undefined,
213213
}, {
214-
messageText: "Argument for '--target' option must be: 'es3', 'es5', 'es6', 'es2015', 'es2016', 'es2017', 'es2018', 'es2019', 'es2020', 'es2021', 'esnext'.",
214+
messageText: "Argument for '--target' option must be: 'es3', 'es5', 'es6', 'es2015', 'es2016', 'es2017', 'es2018', 'es2019', 'es2020', 'es2021', 'es2022', 'esnext'.",
215215
category: Diagnostics.Argument_for_0_option_must_be_Colon_1.category,
216216
code: Diagnostics.Argument_for_0_option_must_be_Colon_1.code,
217217

Diff for: tests/baselines/reference/api/tsserverlibrary.d.ts

+2
Original file line numberDiff line numberDiff line change
@@ -3078,6 +3078,7 @@ declare namespace ts {
30783078
ES2019 = 6,
30793079
ES2020 = 7,
30803080
ES2021 = 8,
3081+
ES2022 = 9,
30813082
ESNext = 99,
30823083
JSON = 100,
30833084
Latest = 99
@@ -9666,6 +9667,7 @@ declare namespace ts.server.protocol {
96669667
ES2019 = "ES2019",
96679668
ES2020 = "ES2020",
96689669
ES2021 = "ES2021",
9670+
ES2022 = "ES2022",
96699671
ESNext = "ESNext"
96709672
}
96719673
enum ClassificationType {

Diff for: tests/baselines/reference/api/typescript.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -3078,6 +3078,7 @@ declare namespace ts {
30783078
ES2019 = 6,
30793079
ES2020 = 7,
30803080
ES2021 = 8,
3081+
ES2022 = 9,
30813082
ESNext = 99,
30823083
JSON = 100,
30833084
Latest = 99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//// [callChainWithSuper.ts]
2+
// GH#34952
3+
class Base { method?() {} }
4+
class Derived extends Base {
5+
method1() { return super.method?.(); }
6+
method2() { return super["method"]?.(); }
7+
}
8+
9+
//// [callChainWithSuper.js]
10+
"use strict";
11+
// GH#34952
12+
class Base {
13+
method() { }
14+
}
15+
class Derived extends Base {
16+
method1() { return super.method?.(); }
17+
method2() { return super["method"]?.(); }
18+
}

Diff for: tests/baselines/reference/callWithSpread4.symbols

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ declare const pli: {
3030

3131
(streams: ReadonlyArray<R | W | RW>): Promise<void>;
3232
>streams : Symbol(streams, Decl(callWithSpread4.ts, 5, 5))
33-
>ReadonlyArray : Symbol(ReadonlyArray, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2016.array.include.d.ts, --, --), Decl(lib.es2019.array.d.ts, --, --))
33+
>ReadonlyArray : Symbol(ReadonlyArray, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2016.array.include.d.ts, --, --), Decl(lib.es2019.array.d.ts, --, --) ... and 1 more)
3434
>R : Symbol(R, Decl(callWithSpread4.ts, 0, 0))
3535
>W : Symbol(W, Decl(callWithSpread4.ts, 0, 22))
3636
>RW : Symbol(RW, Decl(callWithSpread4.ts, 1, 22))
@@ -43,7 +43,7 @@ declare const pli: {
4343
>RW : Symbol(RW, Decl(callWithSpread4.ts, 1, 22))
4444
>W : Symbol(W, Decl(callWithSpread4.ts, 0, 22))
4545
>streams : Symbol(streams, Decl(callWithSpread4.ts, 6, 23))
46-
>Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --) ... and 2 more)
46+
>Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --) ... and 3 more)
4747
>RW : Symbol(RW, Decl(callWithSpread4.ts, 1, 22))
4848
>W : Symbol(W, Decl(callWithSpread4.ts, 0, 22))
4949
>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2018.promise.d.ts, --, --))

Diff for: tests/baselines/reference/doYouNeedToChangeYourTargetLibraryES2016Plus.errors.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ tests/cases/compiler/doYouNeedToChangeYourTargetLibraryES2016Plus.ts(20,27): err
1616
tests/cases/compiler/doYouNeedToChangeYourTargetLibraryES2016Plus.ts(21,35): error TS2583: Cannot find name 'AsyncGeneratorFunction'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2018' or later.
1717
tests/cases/compiler/doYouNeedToChangeYourTargetLibraryES2016Plus.ts(22,26): error TS2583: Cannot find name 'AsyncIterable'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2018' or later.
1818
tests/cases/compiler/doYouNeedToChangeYourTargetLibraryES2016Plus.ts(23,34): error TS2583: Cannot find name 'AsyncIterableIterator'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2018' or later.
19-
tests/cases/compiler/doYouNeedToChangeYourTargetLibraryES2016Plus.ts(24,70): error TS2550: Property 'formatToParts' does not exist on type 'NumberFormat'. Do you need to change your target library? Try changing the 'lib' compiler option to 'esnext' or later.
19+
tests/cases/compiler/doYouNeedToChangeYourTargetLibraryES2016Plus.ts(24,70): error TS2550: Property 'formatToParts' does not exist on type 'NumberFormat'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2018' or later.
2020
tests/cases/compiler/doYouNeedToChangeYourTargetLibraryES2016Plus.ts(27,26): error TS2550: Property 'flat' does not exist on type 'undefined[]'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2019' or later.
2121
tests/cases/compiler/doYouNeedToChangeYourTargetLibraryES2016Plus.ts(28,29): error TS2550: Property 'flatMap' does not exist on type 'undefined[]'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2019' or later.
2222
tests/cases/compiler/doYouNeedToChangeYourTargetLibraryES2016Plus.ts(29,49): error TS2550: Property 'fromEntries' does not exist on type 'ObjectConstructor'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2019' or later.
@@ -95,7 +95,7 @@ tests/cases/compiler/doYouNeedToChangeYourTargetLibraryES2016Plus.ts(44,33): err
9595
!!! error TS2583: Cannot find name 'AsyncIterableIterator'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2018' or later.
9696
const testNumberFormatFormatToParts = new Intl.NumberFormat("en-US").formatToParts();
9797
~~~~~~~~~~~~~
98-
!!! error TS2550: Property 'formatToParts' does not exist on type 'NumberFormat'. Do you need to change your target library? Try changing the 'lib' compiler option to 'esnext' or later.
98+
!!! error TS2550: Property 'formatToParts' does not exist on type 'NumberFormat'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2018' or later.
9999

100100
// es2019
101101
const testArrayFlat = [].flat();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
tests/cases/compiler/errorCause.ts(1,18): error TS2554: Expected 0-1 arguments, but got 2.
2+
3+
4+
==== tests/cases/compiler/errorCause.ts (1 errors) ====
5+
new Error("foo", { cause: new Error("bar") });
6+
~~~~~~~~~~~~~~~~~~~~~~~~~~~
7+
!!! error TS2554: Expected 0-1 arguments, but got 2.
8+

0 commit comments

Comments
 (0)