From 3bac33d3848a249cc6ccab62f9c8757b6c91b3c4 Mon Sep 17 00:00:00 2001 From: Leo Elmecker Date: Thu, 9 Feb 2023 16:17:24 +0000 Subject: [PATCH 01/24] Update 2021 weakref types --- lib/lib.es2021.weakref.d.ts | 9 +++++++-- src/lib/es2021.weakref.d.ts | 4 ++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/lib.es2021.weakref.d.ts b/lib/lib.es2021.weakref.d.ts index eb7764242d7b9..415ee6af8e392 100644 --- a/lib/lib.es2021.weakref.d.ts +++ b/lib/lib.es2021.weakref.d.ts @@ -17,8 +17,13 @@ and limitations under the License. /// +type AllowedWeakTypes = AllowedWeakTypesStore[keyof AllowedWeakTypesStore]; -interface WeakRef { +interface AllowedWeakTypesStore { + object: object; +} + +interface WeakRef { readonly [Symbol.toStringTag]: "WeakRef"; /** @@ -35,7 +40,7 @@ interface WeakRefConstructor { * Creates a WeakRef instance for the given target object. * @param target The target object for the WeakRef instance. */ - new(target: T): WeakRef; + new(target: T): WeakRef; } declare var WeakRef: WeakRefConstructor; diff --git a/src/lib/es2021.weakref.d.ts b/src/lib/es2021.weakref.d.ts index d36ddb6a19cfd..7ab112f32cf58 100644 --- a/src/lib/es2021.weakref.d.ts +++ b/src/lib/es2021.weakref.d.ts @@ -1,4 +1,4 @@ -interface WeakRef { +interface WeakRef { readonly [Symbol.toStringTag]: "WeakRef"; /** @@ -15,7 +15,7 @@ interface WeakRefConstructor { * Creates a WeakRef instance for the given target object. * @param target The target object for the WeakRef instance. */ - new(target: T): WeakRef; + new(target: T): WeakRef; } declare var WeakRef: WeakRefConstructor; From 5871e83e5024e1ee9968b23acdfbdb765141d8c1 Mon Sep 17 00:00:00 2001 From: Leo Elmecker Date: Thu, 9 Feb 2023 16:17:51 +0000 Subject: [PATCH 02/24] Add symbol to WeakRef and FinalizationRegistry --- src/lib/es2023.collection.d.ts | 7 +++++++ src/lib/es2023.weakref.d.ts | 20 ++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 src/lib/es2023.collection.d.ts create mode 100644 src/lib/es2023.weakref.d.ts diff --git a/src/lib/es2023.collection.d.ts b/src/lib/es2023.collection.d.ts new file mode 100644 index 0000000000000..b03c2cde4ef8d --- /dev/null +++ b/src/lib/es2023.collection.d.ts @@ -0,0 +1,7 @@ +interface WeakMapConstructor { + new (entries?: readonly [K, V][] | null): WeakMap; +} + +interface WeakSetConstructor { + new (values?: readonly T[] | null): WeakSet; +} \ No newline at end of file diff --git a/src/lib/es2023.weakref.d.ts b/src/lib/es2023.weakref.d.ts new file mode 100644 index 0000000000000..e8ab6648e8c01 --- /dev/null +++ b/src/lib/es2023.weakref.d.ts @@ -0,0 +1,20 @@ +interface AllowedWeakTypesStore { + symbol: symbol; +} + +interface FinalizationRegistry { + register(target: symbol, heldValue: T, unregisterToken?: symbol): void + unregister(unregisterToken: symbol): void; +} + +interface WeakRef { + /** + * Returns the WeakRef instance's target object, or undefined if the target object has been + * reclaimed. + */ + deref(): T | undefined; +} + +interface WeakRefConstructor { + new(target: T): WeakRef; +} \ No newline at end of file From c0161d95b20e7fae1c2ac4d1b8642116cd5e6999 Mon Sep 17 00:00:00 2001 From: Leo Elmecker Date: Sun, 5 Mar 2023 23:16:53 +0000 Subject: [PATCH 03/24] Update WeakSet keys --- lib/lib.es2015.collection.d.ts | 12 +++++++++--- lib/lib.es2015.iterable.d.ts | 4 ++-- lib/lib.es2015.symbol.wellknown.d.ts | 2 +- lib/lib.es2021.weakref.d.ts | 8 ++++---- src/lib/es2015.collection.d.ts | 6 +++--- src/lib/es2015.iterable.d.ts | 4 ++-- src/lib/es2015.symbol.wellknown.d.ts | 2 +- src/lib/es2021.weakref.d.ts | 4 ++-- src/lib/es2023.collection.d.ts | 6 +++--- src/lib/es2023.weakref.d.ts | 6 +++--- tests/cases/compiler/forwardDeclaredCommonTypes01.ts | 2 +- 11 files changed, 31 insertions(+), 25 deletions(-) diff --git a/lib/lib.es2015.collection.d.ts b/lib/lib.es2015.collection.d.ts index c2e7733ae54b4..10a4a0a7bf0d8 100644 --- a/lib/lib.es2015.collection.d.ts +++ b/lib/lib.es2015.collection.d.ts @@ -127,7 +127,13 @@ interface ReadonlySet { readonly size: number; } -interface WeakSet { +type WeakKeyTypes = WeakKeyTypesStore[keyof WeakKeyTypesStore]; + +interface WeakKeyTypesStore { + object: object; +} + +interface WeakSet { /** * Appends a new object to the end of the WeakSet. */ @@ -144,7 +150,7 @@ interface WeakSet { } interface WeakSetConstructor { - new (values?: readonly T[] | null): WeakSet; - readonly prototype: WeakSet; + new (values?: readonly T[] | null): WeakSet; + readonly prototype: WeakSet; } declare var WeakSet: WeakSetConstructor; diff --git a/lib/lib.es2015.iterable.d.ts b/lib/lib.es2015.iterable.d.ts index 8a7292383442d..0e7ea95e16fa0 100644 --- a/lib/lib.es2015.iterable.d.ts +++ b/lib/lib.es2015.iterable.d.ts @@ -209,10 +209,10 @@ interface SetConstructor { new (iterable?: Iterable | null): Set; } -interface WeakSet { } +interface WeakSet { } interface WeakSetConstructor { - new (iterable: Iterable): WeakSet; + new (iterable: Iterable): WeakSet; } interface Promise { } diff --git a/lib/lib.es2015.symbol.wellknown.d.ts b/lib/lib.es2015.symbol.wellknown.d.ts index 81e052bf26d27..e311fe7492d7f 100644 --- a/lib/lib.es2015.symbol.wellknown.d.ts +++ b/lib/lib.es2015.symbol.wellknown.d.ts @@ -143,7 +143,7 @@ interface Set { readonly [Symbol.toStringTag]: string; } -interface WeakSet { +interface WeakSet { readonly [Symbol.toStringTag]: string; } diff --git a/lib/lib.es2021.weakref.d.ts b/lib/lib.es2021.weakref.d.ts index 415ee6af8e392..b9f9aeed3378c 100644 --- a/lib/lib.es2021.weakref.d.ts +++ b/lib/lib.es2021.weakref.d.ts @@ -17,13 +17,13 @@ and limitations under the License. /// -type AllowedWeakTypes = AllowedWeakTypesStore[keyof AllowedWeakTypesStore]; +type WeakKeyTypes = WeakKeyTypesStore[keyof WeakKeyTypesStore]; -interface AllowedWeakTypesStore { +interface WeakKeyTypesStore { object: object; } -interface WeakRef { +interface WeakRef { readonly [Symbol.toStringTag]: "WeakRef"; /** @@ -40,7 +40,7 @@ interface WeakRefConstructor { * Creates a WeakRef instance for the given target object. * @param target The target object for the WeakRef instance. */ - new(target: T): WeakRef; + new(target: T): WeakRef; } declare var WeakRef: WeakRefConstructor; diff --git a/src/lib/es2015.collection.d.ts b/src/lib/es2015.collection.d.ts index 9e27045a5592a..a6f03fa2963b2 100644 --- a/src/lib/es2015.collection.d.ts +++ b/src/lib/es2015.collection.d.ts @@ -107,7 +107,7 @@ interface ReadonlySet { readonly size: number; } -interface WeakSet { +interface WeakSet { /** * Appends a new object to the end of the WeakSet. */ @@ -124,7 +124,7 @@ interface WeakSet { } interface WeakSetConstructor { - new (values?: readonly T[] | null): WeakSet; - readonly prototype: WeakSet; + new (values?: readonly T[] | null): WeakSet; + readonly prototype: WeakSet; } declare var WeakSet: WeakSetConstructor; diff --git a/src/lib/es2015.iterable.d.ts b/src/lib/es2015.iterable.d.ts index f1fb454f980b1..31d5e10382fa7 100644 --- a/src/lib/es2015.iterable.d.ts +++ b/src/lib/es2015.iterable.d.ts @@ -189,10 +189,10 @@ interface SetConstructor { new (iterable?: Iterable | null): Set; } -interface WeakSet { } +interface WeakSet { } interface WeakSetConstructor { - new (iterable: Iterable): WeakSet; + new (iterable: Iterable): WeakSet; } interface Promise { } diff --git a/src/lib/es2015.symbol.wellknown.d.ts b/src/lib/es2015.symbol.wellknown.d.ts index f27dc68850016..72a830fbb383e 100644 --- a/src/lib/es2015.symbol.wellknown.d.ts +++ b/src/lib/es2015.symbol.wellknown.d.ts @@ -123,7 +123,7 @@ interface Set { readonly [Symbol.toStringTag]: string; } -interface WeakSet { +interface WeakSet { readonly [Symbol.toStringTag]: string; } diff --git a/src/lib/es2021.weakref.d.ts b/src/lib/es2021.weakref.d.ts index 7ab112f32cf58..aa8345e2d5886 100644 --- a/src/lib/es2021.weakref.d.ts +++ b/src/lib/es2021.weakref.d.ts @@ -1,4 +1,4 @@ -interface WeakRef { +interface WeakRef { readonly [Symbol.toStringTag]: "WeakRef"; /** @@ -15,7 +15,7 @@ interface WeakRefConstructor { * Creates a WeakRef instance for the given target object. * @param target The target object for the WeakRef instance. */ - new(target: T): WeakRef; + new(target: T): WeakRef; } declare var WeakRef: WeakRefConstructor; diff --git a/src/lib/es2023.collection.d.ts b/src/lib/es2023.collection.d.ts index b03c2cde4ef8d..4a2868b49bb24 100644 --- a/src/lib/es2023.collection.d.ts +++ b/src/lib/es2023.collection.d.ts @@ -1,7 +1,7 @@ -interface WeakMapConstructor { - new (entries?: readonly [K, V][] | null): WeakMap; +interface WeakSet { + } interface WeakSetConstructor { - new (values?: readonly T[] | null): WeakSet; + new (values?: readonly T[] | null): WeakSet; } \ No newline at end of file diff --git a/src/lib/es2023.weakref.d.ts b/src/lib/es2023.weakref.d.ts index e8ab6648e8c01..e9d00199da909 100644 --- a/src/lib/es2023.weakref.d.ts +++ b/src/lib/es2023.weakref.d.ts @@ -1,4 +1,4 @@ -interface AllowedWeakTypesStore { +interface WeakKeyTypesStore { symbol: symbol; } @@ -7,7 +7,7 @@ interface FinalizationRegistry { unregister(unregisterToken: symbol): void; } -interface WeakRef { +interface WeakRef { /** * Returns the WeakRef instance's target object, or undefined if the target object has been * reclaimed. @@ -16,5 +16,5 @@ interface WeakRef { } interface WeakRefConstructor { - new(target: T): WeakRef; + new(target: T): WeakRef; } \ No newline at end of file diff --git a/tests/cases/compiler/forwardDeclaredCommonTypes01.ts b/tests/cases/compiler/forwardDeclaredCommonTypes01.ts index f4eea80ab0339..931e67ea8de85 100644 --- a/tests/cases/compiler/forwardDeclaredCommonTypes01.ts +++ b/tests/cases/compiler/forwardDeclaredCommonTypes01.ts @@ -6,7 +6,7 @@ interface Symbol {} interface Map {} interface WeakMap {} interface Set {} -interface WeakSet {} +interface WeakSet {} (function() { new Promise; From 0596a4c31f2c1b76cad1ef1eb34bed6fafafe9a3 Mon Sep 17 00:00:00 2001 From: Leo Elmecker Date: Sun, 5 Mar 2023 23:26:01 +0000 Subject: [PATCH 04/24] Add WeakMap symbol support --- lib/lib.es2015.collection.d.ts | 6 ++-- lib/lib.es2015.iterable.d.ts | 4 +-- lib/lib.es2015.symbol.wellknown.d.ts | 2 +- src/lib/es2015.collection.d.ts | 2 +- src/lib/es2015.iterable.d.ts | 4 +-- src/lib/es2015.symbol.wellknown.d.ts | 2 +- src/lib/es2023.collection.d.ts | 13 ++++++-- .../reference/forwardDeclaredCommonTypes01.js | 30 +++++++++---------- .../compiler/forwardDeclaredCommonTypes01.ts | 2 +- 9 files changed, 37 insertions(+), 28 deletions(-) diff --git a/lib/lib.es2015.collection.d.ts b/lib/lib.es2015.collection.d.ts index 10a4a0a7bf0d8..ab842750c3984 100644 --- a/lib/lib.es2015.collection.d.ts +++ b/lib/lib.es2015.collection.d.ts @@ -62,7 +62,7 @@ interface ReadonlyMap { readonly size: number; } -interface WeakMap { +interface WeakMap { /** * Removes the specified element from the WeakMap. * @returns true if the element was successfully removed, or false if it was not present. @@ -84,8 +84,8 @@ interface WeakMap { } interface WeakMapConstructor { - new (entries?: readonly [K, V][] | null): WeakMap; - readonly prototype: WeakMap; + new (entries?: readonly [K, V][] | null): WeakMap; + readonly prototype: WeakMap; } declare var WeakMap: WeakMapConstructor; diff --git a/lib/lib.es2015.iterable.d.ts b/lib/lib.es2015.iterable.d.ts index 0e7ea95e16fa0..fecd3024f366c 100644 --- a/lib/lib.es2015.iterable.d.ts +++ b/lib/lib.es2015.iterable.d.ts @@ -161,10 +161,10 @@ interface MapConstructor { new (iterable?: Iterable | null): Map; } -interface WeakMap { } +interface WeakMap { } interface WeakMapConstructor { - new (iterable: Iterable): WeakMap; + new (iterable: Iterable): WeakMap; } interface Set { diff --git a/lib/lib.es2015.symbol.wellknown.d.ts b/lib/lib.es2015.symbol.wellknown.d.ts index e311fe7492d7f..13b265343321b 100644 --- a/lib/lib.es2015.symbol.wellknown.d.ts +++ b/lib/lib.es2015.symbol.wellknown.d.ts @@ -135,7 +135,7 @@ interface Map { readonly [Symbol.toStringTag]: string; } -interface WeakMap { +interface WeakMap { readonly [Symbol.toStringTag]: string; } diff --git a/src/lib/es2015.collection.d.ts b/src/lib/es2015.collection.d.ts index a6f03fa2963b2..ecb4f27cbd881 100644 --- a/src/lib/es2015.collection.d.ts +++ b/src/lib/es2015.collection.d.ts @@ -42,7 +42,7 @@ interface ReadonlyMap { readonly size: number; } -interface WeakMap { +interface WeakMap { /** * Removes the specified element from the WeakMap. * @returns true if the element was successfully removed, or false if it was not present. diff --git a/src/lib/es2015.iterable.d.ts b/src/lib/es2015.iterable.d.ts index 31d5e10382fa7..ac5fe27670c78 100644 --- a/src/lib/es2015.iterable.d.ts +++ b/src/lib/es2015.iterable.d.ts @@ -141,10 +141,10 @@ interface MapConstructor { new (iterable?: Iterable | null): Map; } -interface WeakMap { } +interface WeakMap { } interface WeakMapConstructor { - new (iterable: Iterable): WeakMap; + new (iterable: Iterable): WeakMap; } interface Set { diff --git a/src/lib/es2015.symbol.wellknown.d.ts b/src/lib/es2015.symbol.wellknown.d.ts index 72a830fbb383e..643f402ea62b6 100644 --- a/src/lib/es2015.symbol.wellknown.d.ts +++ b/src/lib/es2015.symbol.wellknown.d.ts @@ -115,7 +115,7 @@ interface Map { readonly [Symbol.toStringTag]: string; } -interface WeakMap { +interface WeakMap { readonly [Symbol.toStringTag]: string; } diff --git a/src/lib/es2023.collection.d.ts b/src/lib/es2023.collection.d.ts index 4a2868b49bb24..cfc69183956fe 100644 --- a/src/lib/es2023.collection.d.ts +++ b/src/lib/es2023.collection.d.ts @@ -1,7 +1,16 @@ -interface WeakSet { - +interface WeakKeyTypesStore { + symbol: symbol; } +interface WeakSet {} + interface WeakSetConstructor { new (values?: readonly T[] | null): WeakSet; +} + +interface WeakMap {} + +interface WeakMapConstructor { + new (entries?: readonly [K, V][] | null): WeakMap; + readonly prototype: WeakMap; } \ No newline at end of file diff --git a/tests/baselines/reference/forwardDeclaredCommonTypes01.js b/tests/baselines/reference/forwardDeclaredCommonTypes01.js index 5177852443034..83743b2f3a2a4 100644 --- a/tests/baselines/reference/forwardDeclaredCommonTypes01.js +++ b/tests/baselines/reference/forwardDeclaredCommonTypes01.js @@ -1,10 +1,10 @@ -//// [forwardDeclaredCommonTypes01.ts] +//// [forwardDeclaredCommonTypes01.ts] interface Promise {} interface Symbol {} interface Map {} -interface WeakMap {} +interface WeakMap {} interface Set {} -interface WeakSet {} +interface WeakSet {} (function() { new Promise; @@ -14,15 +14,15 @@ interface WeakSet {} new Set; new WeakSet; }); - - -//// [forwardDeclaredCommonTypes01.js] -(function () { - new Promise; - new Symbol; - Symbol(); - new Map; - new WeakMap; - new Set; - new WeakSet; -}); + + +//// [forwardDeclaredCommonTypes01.js] +(function () { + new Promise; + new Symbol; + Symbol(); + new Map; + new WeakMap; + new Set; + new WeakSet; +}); diff --git a/tests/cases/compiler/forwardDeclaredCommonTypes01.ts b/tests/cases/compiler/forwardDeclaredCommonTypes01.ts index 931e67ea8de85..b9e69f1383b4b 100644 --- a/tests/cases/compiler/forwardDeclaredCommonTypes01.ts +++ b/tests/cases/compiler/forwardDeclaredCommonTypes01.ts @@ -4,7 +4,7 @@ interface Promise {} interface Symbol {} interface Map {} -interface WeakMap {} +interface WeakMap {} interface Set {} interface WeakSet {} From 776c6a70d2772b4bd7f3574cc5019b14212a12e1 Mon Sep 17 00:00:00 2001 From: Leo Elmecker Date: Tue, 14 Mar 2023 18:34:37 +0000 Subject: [PATCH 05/24] Resolve compilation and testing issues --- src/compiler/commandLineParser.ts | 2 ++ src/lib/es2015.collection.d.ts | 6 ++++ src/lib/es2023.d.ts | 1 + src/lib/libs.json | 1 + .../reference/acceptSymbolAsWeakType.js | 10 ++++++ .../dissallowSymbolAsWeakType.errors.txt | 31 +++++++++++++++++++ .../reference/dissallowSymbolAsWeakType.js | 10 ++++++ .../reference/forwardDeclaredCommonTypes01.js | 30 +++++++++--------- .../cases/compiler/acceptSymbolAsWeakType.ts | 7 +++++ .../compiler/dissallowSymbolAsWeakType.ts | 7 +++++ .../compiler/forwardDeclaredCommonTypes01.ts | 4 +-- 11 files changed, 92 insertions(+), 17 deletions(-) create mode 100644 tests/baselines/reference/acceptSymbolAsWeakType.js create mode 100644 tests/baselines/reference/dissallowSymbolAsWeakType.errors.txt create mode 100644 tests/baselines/reference/dissallowSymbolAsWeakType.js create mode 100644 tests/cases/compiler/acceptSymbolAsWeakType.ts create mode 100644 tests/cases/compiler/dissallowSymbolAsWeakType.ts diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 629063de29808..1f0ff1362421d 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -211,7 +211,9 @@ const libEntries: [string, string][] = [ ["es2022.string", "lib.es2022.string.d.ts"], ["es2022.regexp", "lib.es2022.regexp.d.ts"], ["es2023.array", "lib.es2023.array.d.ts"], + ["es2023.collection", "lib.es2023.collection.d.ts"], ["esnext.array", "lib.es2023.array.d.ts"], + ["esnext.array", "lib.es2023.collection.d.ts"], ["esnext.symbol", "lib.es2019.symbol.d.ts"], ["esnext.asynciterable", "lib.es2018.asynciterable.d.ts"], ["esnext.intl", "lib.esnext.intl.d.ts"], diff --git a/src/lib/es2015.collection.d.ts b/src/lib/es2015.collection.d.ts index ecb4f27cbd881..3ab7175543949 100644 --- a/src/lib/es2015.collection.d.ts +++ b/src/lib/es2015.collection.d.ts @@ -42,6 +42,12 @@ interface ReadonlyMap { readonly size: number; } +type WeakKeyTypes = WeakKeyTypesStore[keyof WeakKeyTypesStore]; + +interface WeakKeyTypesStore { + object: object; +} + interface WeakMap { /** * Removes the specified element from the WeakMap. diff --git a/src/lib/es2023.d.ts b/src/lib/es2023.d.ts index 02292dc39546f..5c45f807e08a8 100644 --- a/src/lib/es2023.d.ts +++ b/src/lib/es2023.d.ts @@ -1,2 +1,3 @@ /// /// +/// diff --git a/src/lib/libs.json b/src/lib/libs.json index 82ba97aa35fb8..5613674ef77d5 100644 --- a/src/lib/libs.json +++ b/src/lib/libs.json @@ -65,6 +65,7 @@ "es2022.string", "es2022.regexp", "es2023.array", + "es2023.collection", "esnext.intl", "decorators", "decorators.legacy", diff --git a/tests/baselines/reference/acceptSymbolAsWeakType.js b/tests/baselines/reference/acceptSymbolAsWeakType.js new file mode 100644 index 0000000000000..d855204aa12c7 --- /dev/null +++ b/tests/baselines/reference/acceptSymbolAsWeakType.js @@ -0,0 +1,10 @@ +//// [acceptSymbolAsWeakType.ts] +const s: symbol = Symbol('s'); + +const ws = new WeakSet([s]); +ws.add(s); + +//// [acceptSymbolAsWeakType.js] +const s = Symbol('s'); +const ws = new WeakSet([s]); +ws.add(s); diff --git a/tests/baselines/reference/dissallowSymbolAsWeakType.errors.txt b/tests/baselines/reference/dissallowSymbolAsWeakType.errors.txt new file mode 100644 index 0000000000000..7d17aeaf5d614 --- /dev/null +++ b/tests/baselines/reference/dissallowSymbolAsWeakType.errors.txt @@ -0,0 +1,31 @@ +tests/cases/compiler/dissallowSymbolAsWeakType.ts(3,12): error TS2769: No overload matches this call. + Overload 1 of 2, '(iterable: Iterable): WeakSet', gave the following error. + Argument of type 'symbol[]' is not assignable to parameter of type 'Iterable'. + The types returned by '[Symbol.iterator]().next(...)' are incompatible between these types. + Type 'IteratorResult' is not assignable to type 'IteratorResult'. + Type 'IteratorYieldResult' is not assignable to type 'IteratorResult'. + Type 'IteratorYieldResult' is not assignable to type 'IteratorYieldResult'. + Type 'symbol' is not assignable to type 'object'. + Overload 2 of 2, '(values?: readonly object[]): WeakSet', gave the following error. + Type 'symbol' is not assignable to type 'object'. +tests/cases/compiler/dissallowSymbolAsWeakType.ts(4,8): error TS2345: Argument of type 'symbol' is not assignable to parameter of type 'object'. + + +==== tests/cases/compiler/dissallowSymbolAsWeakType.ts (2 errors) ==== + const s: symbol = Symbol('s'); + + const ws = new WeakSet([s]); + ~~~~~~~~~~~~~~~~ +!!! error TS2769: No overload matches this call. +!!! error TS2769: Overload 1 of 2, '(iterable: Iterable): WeakSet', gave the following error. +!!! error TS2769: Argument of type 'symbol[]' is not assignable to parameter of type 'Iterable'. +!!! error TS2769: The types returned by '[Symbol.iterator]().next(...)' are incompatible between these types. +!!! error TS2769: Type 'IteratorResult' is not assignable to type 'IteratorResult'. +!!! error TS2769: Type 'IteratorYieldResult' is not assignable to type 'IteratorResult'. +!!! error TS2769: Type 'IteratorYieldResult' is not assignable to type 'IteratorYieldResult'. +!!! error TS2769: Type 'symbol' is not assignable to type 'object'. +!!! error TS2769: Overload 2 of 2, '(values?: readonly object[]): WeakSet', gave the following error. +!!! error TS2769: Type 'symbol' is not assignable to type 'object'. + ws.add(s); + ~ +!!! error TS2345: Argument of type 'symbol' is not assignable to parameter of type 'object'. \ No newline at end of file diff --git a/tests/baselines/reference/dissallowSymbolAsWeakType.js b/tests/baselines/reference/dissallowSymbolAsWeakType.js new file mode 100644 index 0000000000000..a670ac34b2bd3 --- /dev/null +++ b/tests/baselines/reference/dissallowSymbolAsWeakType.js @@ -0,0 +1,10 @@ +//// [dissallowSymbolAsWeakType.ts] +const s: symbol = Symbol('s'); + +const ws = new WeakSet([s]); +ws.add(s); + +//// [dissallowSymbolAsWeakType.js] +const s = Symbol('s'); +const ws = new WeakSet([s]); +ws.add(s); diff --git a/tests/baselines/reference/forwardDeclaredCommonTypes01.js b/tests/baselines/reference/forwardDeclaredCommonTypes01.js index 83743b2f3a2a4..5177852443034 100644 --- a/tests/baselines/reference/forwardDeclaredCommonTypes01.js +++ b/tests/baselines/reference/forwardDeclaredCommonTypes01.js @@ -1,10 +1,10 @@ -//// [forwardDeclaredCommonTypes01.ts] +//// [forwardDeclaredCommonTypes01.ts] interface Promise {} interface Symbol {} interface Map {} -interface WeakMap {} +interface WeakMap {} interface Set {} -interface WeakSet {} +interface WeakSet {} (function() { new Promise; @@ -14,15 +14,15 @@ interface WeakSet {} new Set; new WeakSet; }); - - -//// [forwardDeclaredCommonTypes01.js] -(function () { - new Promise; - new Symbol; - Symbol(); - new Map; - new WeakMap; - new Set; - new WeakSet; -}); + + +//// [forwardDeclaredCommonTypes01.js] +(function () { + new Promise; + new Symbol; + Symbol(); + new Map; + new WeakMap; + new Set; + new WeakSet; +}); diff --git a/tests/cases/compiler/acceptSymbolAsWeakType.ts b/tests/cases/compiler/acceptSymbolAsWeakType.ts new file mode 100644 index 0000000000000..5cf02fa473837 --- /dev/null +++ b/tests/cases/compiler/acceptSymbolAsWeakType.ts @@ -0,0 +1,7 @@ +// @lib: esnext +// @target: esnext + +const s: symbol = Symbol('s'); + +const ws = new WeakSet([s]); +ws.add(s); \ No newline at end of file diff --git a/tests/cases/compiler/dissallowSymbolAsWeakType.ts b/tests/cases/compiler/dissallowSymbolAsWeakType.ts new file mode 100644 index 0000000000000..7b7f98fb7c548 --- /dev/null +++ b/tests/cases/compiler/dissallowSymbolAsWeakType.ts @@ -0,0 +1,7 @@ +// @lib: es2022 +// @target: es2022 + +const s: symbol = Symbol('s'); + +const ws = new WeakSet([s]); +ws.add(s); \ No newline at end of file diff --git a/tests/cases/compiler/forwardDeclaredCommonTypes01.ts b/tests/cases/compiler/forwardDeclaredCommonTypes01.ts index b9e69f1383b4b..f4eea80ab0339 100644 --- a/tests/cases/compiler/forwardDeclaredCommonTypes01.ts +++ b/tests/cases/compiler/forwardDeclaredCommonTypes01.ts @@ -4,9 +4,9 @@ interface Promise {} interface Symbol {} interface Map {} -interface WeakMap {} +interface WeakMap {} interface Set {} -interface WeakSet {} +interface WeakSet {} (function() { new Promise; From 4b02a2c30d107fb353170ec4a76e7a934d25f8a7 Mon Sep 17 00:00:00 2001 From: Leo Elmecker Date: Thu, 16 Mar 2023 16:55:22 +0000 Subject: [PATCH 06/24] Add some test changes --- tests/cases/compiler/acceptSymbolAsWeakType.ts | 10 +++++++++- tests/cases/compiler/dissallowSymbolAsWeakType.ts | 10 +++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/tests/cases/compiler/acceptSymbolAsWeakType.ts b/tests/cases/compiler/acceptSymbolAsWeakType.ts index 5cf02fa473837..3c1fc9b6c2068 100644 --- a/tests/cases/compiler/acceptSymbolAsWeakType.ts +++ b/tests/cases/compiler/acceptSymbolAsWeakType.ts @@ -4,4 +4,12 @@ const s: symbol = Symbol('s'); const ws = new WeakSet([s]); -ws.add(s); \ No newline at end of file +ws.add(s); +ws.has(s); +ws.delete(s); + +const wm = new WeakMap([[s, false]]); +wm.set(s, true); +wm.has(s); +wm.get(s); +wm.delete(s); \ No newline at end of file diff --git a/tests/cases/compiler/dissallowSymbolAsWeakType.ts b/tests/cases/compiler/dissallowSymbolAsWeakType.ts index 7b7f98fb7c548..88d27a3c55b8b 100644 --- a/tests/cases/compiler/dissallowSymbolAsWeakType.ts +++ b/tests/cases/compiler/dissallowSymbolAsWeakType.ts @@ -4,4 +4,12 @@ const s: symbol = Symbol('s'); const ws = new WeakSet([s]); -ws.add(s); \ No newline at end of file +ws.add(s); +ws.has(s); +ws.delete(s); + +const wm = new WeakMap([[s, false]]); +wm.set(s, true); +wm.has(s); +wm.get(s); +wm.delete(s); From 0e809bfef7a0c61fcd0ec0dbe414864820bf999f Mon Sep 17 00:00:00 2001 From: Leo Elmecker Date: Wed, 22 Mar 2023 23:49:37 +0000 Subject: [PATCH 07/24] Add testing for WeakRef and FinalizationRegistry --- lib/lib.es2021.weakref.d.ts | 8 +-- src/compiler/commandLineParser.ts | 2 + src/lib/es2023.d.ts | 1 + src/lib/es2023.weakref.d.ts | 33 ++++++++- src/lib/libs.json | 1 + .../reference/acceptSymbolAsWeakType.js | 29 +++++++- .../dissallowSymbolAsWeakType.errors.txt | 72 ++++++++++++++++++- .../reference/dissallowSymbolAsWeakType.js | 30 +++++++- .../cases/compiler/acceptSymbolAsWeakType.ts | 9 ++- .../compiler/dissallowSymbolAsWeakType.ts | 7 ++ 10 files changed, 178 insertions(+), 14 deletions(-) diff --git a/lib/lib.es2021.weakref.d.ts b/lib/lib.es2021.weakref.d.ts index b9f9aeed3378c..6f67efd50315c 100644 --- a/lib/lib.es2021.weakref.d.ts +++ b/lib/lib.es2021.weakref.d.ts @@ -17,12 +17,6 @@ and limitations under the License. /// -type WeakKeyTypes = WeakKeyTypesStore[keyof WeakKeyTypesStore]; - -interface WeakKeyTypesStore { - object: object; -} - interface WeakRef { readonly [Symbol.toStringTag]: "WeakRef"; @@ -57,7 +51,7 @@ interface FinalizationRegistry { * object. If provided (and not undefined), this must be an object. If not provided, the target * cannot be unregistered. */ - register(target: object, heldValue: T, unregisterToken?: object): void; + register(target: symbol, heldValue: T, unregisterToken?: symbol): void; /** * Unregisters an object from the registry. diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 1f0ff1362421d..1343e9d461b76 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -212,8 +212,10 @@ const libEntries: [string, string][] = [ ["es2022.regexp", "lib.es2022.regexp.d.ts"], ["es2023.array", "lib.es2023.array.d.ts"], ["es2023.collection", "lib.es2023.collection.d.ts"], + ["es2023.weakref", "lib.es2023.weakref.d.ts"], ["esnext.array", "lib.es2023.array.d.ts"], ["esnext.array", "lib.es2023.collection.d.ts"], + ["esnext.array", "lib.es2023.weakref.d.ts"], ["esnext.symbol", "lib.es2019.symbol.d.ts"], ["esnext.asynciterable", "lib.es2018.asynciterable.d.ts"], ["esnext.intl", "lib.esnext.intl.d.ts"], diff --git a/src/lib/es2023.d.ts b/src/lib/es2023.d.ts index 5c45f807e08a8..243142c103eda 100644 --- a/src/lib/es2023.d.ts +++ b/src/lib/es2023.d.ts @@ -1,3 +1,4 @@ /// /// /// +/// diff --git a/src/lib/es2023.weakref.d.ts b/src/lib/es2023.weakref.d.ts index e9d00199da909..609dda30b3349 100644 --- a/src/lib/es2023.weakref.d.ts +++ b/src/lib/es2023.weakref.d.ts @@ -3,10 +3,39 @@ interface WeakKeyTypesStore { } interface FinalizationRegistry { - register(target: symbol, heldValue: T, unregisterToken?: symbol): void - unregister(unregisterToken: symbol): void; + readonly [Symbol.toStringTag]: "FinalizationRegistry"; + + /** + * Registers an object with the registry. + * @param target The target object to register. + * @param heldValue The value to pass to the finalizer for this object. This cannot be the + * target object. + * @param unregisterToken The token to pass to the unregister method to unregister the target + * object. If provided (and not undefined), this must be an object. If not provided, the target + * cannot be unregistered. + */ + registerSymbol(target: symbol, heldValue: T, unregisterToken?: symbol): void; + + /** + * Unregisters an object from the registry. + * @param unregisterToken The token that was used as the unregisterToken argument when calling + * register to register the target object. + */ + unregisterSymbol(unregisterToken: symbol): void; } +interface FinalizationRegistryConstructor { + readonly prototype: FinalizationRegistry; + + /** + * Creates a finalization registry with an associated cleanup callback + * @param cleanupCallback The callback to call after an object in the registry has been reclaimed. + */ + new(cleanupCallback: (heldValue: T) => void): FinalizationRegistry; +} + +declare var FinalizationRegistry: FinalizationRegistryConstructor; + interface WeakRef { /** * Returns the WeakRef instance's target object, or undefined if the target object has been diff --git a/src/lib/libs.json b/src/lib/libs.json index 5613674ef77d5..27432a738d42b 100644 --- a/src/lib/libs.json +++ b/src/lib/libs.json @@ -66,6 +66,7 @@ "es2022.regexp", "es2023.array", "es2023.collection", + "es2023.weakref", "esnext.intl", "decorators", "decorators.legacy", diff --git a/tests/baselines/reference/acceptSymbolAsWeakType.js b/tests/baselines/reference/acceptSymbolAsWeakType.js index d855204aa12c7..d562d9cce9157 100644 --- a/tests/baselines/reference/acceptSymbolAsWeakType.js +++ b/tests/baselines/reference/acceptSymbolAsWeakType.js @@ -2,9 +2,36 @@ const s: symbol = Symbol('s'); const ws = new WeakSet([s]); -ws.add(s); +ws.add(s); +ws.has(s); +ws.delete(s); + +const wm = new WeakMap([[s, false]]); +wm.set(s, true); +wm.has(s); +wm.get(s); +wm.delete(s); + +const wr = new WeakRef(s); +wr.deref(); + +const f = new FinalizationRegistry(() => {}); +f.registerSymbol(s, null); +f.unregisterSymbol(s); //// [acceptSymbolAsWeakType.js] const s = Symbol('s'); const ws = new WeakSet([s]); ws.add(s); +ws.has(s); +ws.delete(s); +const wm = new WeakMap([[s, false]]); +wm.set(s, true); +wm.has(s); +wm.get(s); +wm.delete(s); +const wr = new WeakRef(s); +wr.deref(); +const f = new FinalizationRegistry(() => { }); +f.registerSymbol(s, null); +f.unregisterSymbol(s); diff --git a/tests/baselines/reference/dissallowSymbolAsWeakType.errors.txt b/tests/baselines/reference/dissallowSymbolAsWeakType.errors.txt index 7d17aeaf5d614..8f723a128e693 100644 --- a/tests/baselines/reference/dissallowSymbolAsWeakType.errors.txt +++ b/tests/baselines/reference/dissallowSymbolAsWeakType.errors.txt @@ -9,9 +9,30 @@ tests/cases/compiler/dissallowSymbolAsWeakType.ts(3,12): error TS2769: No overlo Overload 2 of 2, '(values?: readonly object[]): WeakSet', gave the following error. Type 'symbol' is not assignable to type 'object'. tests/cases/compiler/dissallowSymbolAsWeakType.ts(4,8): error TS2345: Argument of type 'symbol' is not assignable to parameter of type 'object'. +tests/cases/compiler/dissallowSymbolAsWeakType.ts(5,8): error TS2345: Argument of type 'symbol' is not assignable to parameter of type 'object'. +tests/cases/compiler/dissallowSymbolAsWeakType.ts(6,11): error TS2345: Argument of type 'symbol' is not assignable to parameter of type 'object'. +tests/cases/compiler/dissallowSymbolAsWeakType.ts(8,12): error TS2769: No overload matches this call. + Overload 1 of 2, '(iterable: Iterable): WeakMap', gave the following error. + Argument of type '[symbol, false][]' is not assignable to parameter of type 'Iterable'. + The types returned by '[Symbol.iterator]().next(...)' are incompatible between these types. + Type 'IteratorResult<[symbol, false], any>' is not assignable to type 'IteratorResult'. + Type 'IteratorYieldResult<[symbol, false]>' is not assignable to type 'IteratorResult'. + Type 'IteratorYieldResult<[symbol, false]>' is not assignable to type 'IteratorYieldResult'. + Type '[symbol, false]' is not assignable to type 'readonly [object, boolean]'. + Type at position 0 in source is not compatible with type at position 0 in target. + Type 'symbol' is not assignable to type 'object'. + Overload 2 of 2, '(entries?: readonly [object, boolean][]): WeakMap', gave the following error. + Type 'symbol' is not assignable to type 'object'. +tests/cases/compiler/dissallowSymbolAsWeakType.ts(9,8): error TS2345: Argument of type 'symbol' is not assignable to parameter of type 'object'. +tests/cases/compiler/dissallowSymbolAsWeakType.ts(10,8): error TS2345: Argument of type 'symbol' is not assignable to parameter of type 'object'. +tests/cases/compiler/dissallowSymbolAsWeakType.ts(11,8): error TS2345: Argument of type 'symbol' is not assignable to parameter of type 'object'. +tests/cases/compiler/dissallowSymbolAsWeakType.ts(12,11): error TS2345: Argument of type 'symbol' is not assignable to parameter of type 'object'. +tests/cases/compiler/dissallowSymbolAsWeakType.ts(14,24): error TS2345: Argument of type 'symbol' is not assignable to parameter of type 'object'. +tests/cases/compiler/dissallowSymbolAsWeakType.ts(18,12): error TS2345: Argument of type 'symbol' is not assignable to parameter of type 'object'. +tests/cases/compiler/dissallowSymbolAsWeakType.ts(19,14): error TS2345: Argument of type 'symbol' is not assignable to parameter of type 'object'. -==== tests/cases/compiler/dissallowSymbolAsWeakType.ts (2 errors) ==== +==== tests/cases/compiler/dissallowSymbolAsWeakType.ts (12 errors) ==== const s: symbol = Symbol('s'); const ws = new WeakSet([s]); @@ -28,4 +49,51 @@ tests/cases/compiler/dissallowSymbolAsWeakType.ts(4,8): error TS2345: Argument o !!! error TS2769: Type 'symbol' is not assignable to type 'object'. ws.add(s); ~ -!!! error TS2345: Argument of type 'symbol' is not assignable to parameter of type 'object'. \ No newline at end of file +!!! error TS2345: Argument of type 'symbol' is not assignable to parameter of type 'object'. + ws.has(s); + ~ +!!! error TS2345: Argument of type 'symbol' is not assignable to parameter of type 'object'. + ws.delete(s); + ~ +!!! error TS2345: Argument of type 'symbol' is not assignable to parameter of type 'object'. + + const wm = new WeakMap([[s, false]]); + ~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2769: No overload matches this call. +!!! error TS2769: Overload 1 of 2, '(iterable: Iterable): WeakMap', gave the following error. +!!! error TS2769: Argument of type '[symbol, false][]' is not assignable to parameter of type 'Iterable'. +!!! error TS2769: The types returned by '[Symbol.iterator]().next(...)' are incompatible between these types. +!!! error TS2769: Type 'IteratorResult<[symbol, false], any>' is not assignable to type 'IteratorResult'. +!!! error TS2769: Type 'IteratorYieldResult<[symbol, false]>' is not assignable to type 'IteratorResult'. +!!! error TS2769: Type 'IteratorYieldResult<[symbol, false]>' is not assignable to type 'IteratorYieldResult'. +!!! error TS2769: Type '[symbol, false]' is not assignable to type 'readonly [object, boolean]'. +!!! error TS2769: Type at position 0 in source is not compatible with type at position 0 in target. +!!! error TS2769: Type 'symbol' is not assignable to type 'object'. +!!! error TS2769: Overload 2 of 2, '(entries?: readonly [object, boolean][]): WeakMap', gave the following error. +!!! error TS2769: Type 'symbol' is not assignable to type 'object'. + wm.set(s, true); + ~ +!!! error TS2345: Argument of type 'symbol' is not assignable to parameter of type 'object'. + wm.has(s); + ~ +!!! error TS2345: Argument of type 'symbol' is not assignable to parameter of type 'object'. + wm.get(s); + ~ +!!! error TS2345: Argument of type 'symbol' is not assignable to parameter of type 'object'. + wm.delete(s); + ~ +!!! error TS2345: Argument of type 'symbol' is not assignable to parameter of type 'object'. + + const wr = new WeakRef(s); + ~ +!!! error TS2345: Argument of type 'symbol' is not assignable to parameter of type 'object'. + wr.deref(); + + const f = new FinalizationRegistry(() => {}); + f.register(s, null); + ~ +!!! error TS2345: Argument of type 'symbol' is not assignable to parameter of type 'object'. + f.unregister(s); + ~ +!!! error TS2345: Argument of type 'symbol' is not assignable to parameter of type 'object'. + \ No newline at end of file diff --git a/tests/baselines/reference/dissallowSymbolAsWeakType.js b/tests/baselines/reference/dissallowSymbolAsWeakType.js index a670ac34b2bd3..c9d598f4ee478 100644 --- a/tests/baselines/reference/dissallowSymbolAsWeakType.js +++ b/tests/baselines/reference/dissallowSymbolAsWeakType.js @@ -2,9 +2,37 @@ const s: symbol = Symbol('s'); const ws = new WeakSet([s]); -ws.add(s); +ws.add(s); +ws.has(s); +ws.delete(s); + +const wm = new WeakMap([[s, false]]); +wm.set(s, true); +wm.has(s); +wm.get(s); +wm.delete(s); + +const wr = new WeakRef(s); +wr.deref(); + +const f = new FinalizationRegistry(() => {}); +f.register(s, null); +f.unregister(s); + //// [dissallowSymbolAsWeakType.js] const s = Symbol('s'); const ws = new WeakSet([s]); ws.add(s); +ws.has(s); +ws.delete(s); +const wm = new WeakMap([[s, false]]); +wm.set(s, true); +wm.has(s); +wm.get(s); +wm.delete(s); +const wr = new WeakRef(s); +wr.deref(); +const f = new FinalizationRegistry(() => { }); +f.register(s, null); +f.unregister(s); diff --git a/tests/cases/compiler/acceptSymbolAsWeakType.ts b/tests/cases/compiler/acceptSymbolAsWeakType.ts index 3c1fc9b6c2068..35dc147ac953a 100644 --- a/tests/cases/compiler/acceptSymbolAsWeakType.ts +++ b/tests/cases/compiler/acceptSymbolAsWeakType.ts @@ -12,4 +12,11 @@ const wm = new WeakMap([[s, false]]); wm.set(s, true); wm.has(s); wm.get(s); -wm.delete(s); \ No newline at end of file +wm.delete(s); + +const wr = new WeakRef(s); +wr.deref(); + +const f = new FinalizationRegistry(() => {}); +f.registerSymbol(s, null); +f.unregisterSymbol(s); \ No newline at end of file diff --git a/tests/cases/compiler/dissallowSymbolAsWeakType.ts b/tests/cases/compiler/dissallowSymbolAsWeakType.ts index 88d27a3c55b8b..e6f43b495aead 100644 --- a/tests/cases/compiler/dissallowSymbolAsWeakType.ts +++ b/tests/cases/compiler/dissallowSymbolAsWeakType.ts @@ -13,3 +13,10 @@ wm.set(s, true); wm.has(s); wm.get(s); wm.delete(s); + +const wr = new WeakRef(s); +wr.deref(); + +const f = new FinalizationRegistry(() => {}); +f.register(s, null); +f.unregister(s); From 224130631169f6202efb7de578c7e99611280745 Mon Sep 17 00:00:00 2001 From: Leo Elmecker Date: Thu, 23 Mar 2023 00:18:36 +0000 Subject: [PATCH 08/24] Undo lib changes --- lib/lib.es2015.collection.d.ts | 18 ++++++------------ lib/lib.es2015.iterable.d.ts | 8 ++++---- lib/lib.es2015.symbol.wellknown.d.ts | 4 ++-- lib/lib.es2021.weakref.d.ts | 6 +++--- 4 files changed, 15 insertions(+), 21 deletions(-) diff --git a/lib/lib.es2015.collection.d.ts b/lib/lib.es2015.collection.d.ts index ab842750c3984..c2e7733ae54b4 100644 --- a/lib/lib.es2015.collection.d.ts +++ b/lib/lib.es2015.collection.d.ts @@ -62,7 +62,7 @@ interface ReadonlyMap { readonly size: number; } -interface WeakMap { +interface WeakMap { /** * Removes the specified element from the WeakMap. * @returns true if the element was successfully removed, or false if it was not present. @@ -84,8 +84,8 @@ interface WeakMap { } interface WeakMapConstructor { - new (entries?: readonly [K, V][] | null): WeakMap; - readonly prototype: WeakMap; + new (entries?: readonly [K, V][] | null): WeakMap; + readonly prototype: WeakMap; } declare var WeakMap: WeakMapConstructor; @@ -127,13 +127,7 @@ interface ReadonlySet { readonly size: number; } -type WeakKeyTypes = WeakKeyTypesStore[keyof WeakKeyTypesStore]; - -interface WeakKeyTypesStore { - object: object; -} - -interface WeakSet { +interface WeakSet { /** * Appends a new object to the end of the WeakSet. */ @@ -150,7 +144,7 @@ interface WeakSet { } interface WeakSetConstructor { - new (values?: readonly T[] | null): WeakSet; - readonly prototype: WeakSet; + new (values?: readonly T[] | null): WeakSet; + readonly prototype: WeakSet; } declare var WeakSet: WeakSetConstructor; diff --git a/lib/lib.es2015.iterable.d.ts b/lib/lib.es2015.iterable.d.ts index fecd3024f366c..8a7292383442d 100644 --- a/lib/lib.es2015.iterable.d.ts +++ b/lib/lib.es2015.iterable.d.ts @@ -161,10 +161,10 @@ interface MapConstructor { new (iterable?: Iterable | null): Map; } -interface WeakMap { } +interface WeakMap { } interface WeakMapConstructor { - new (iterable: Iterable): WeakMap; + new (iterable: Iterable): WeakMap; } interface Set { @@ -209,10 +209,10 @@ interface SetConstructor { new (iterable?: Iterable | null): Set; } -interface WeakSet { } +interface WeakSet { } interface WeakSetConstructor { - new (iterable: Iterable): WeakSet; + new (iterable: Iterable): WeakSet; } interface Promise { } diff --git a/lib/lib.es2015.symbol.wellknown.d.ts b/lib/lib.es2015.symbol.wellknown.d.ts index 13b265343321b..81e052bf26d27 100644 --- a/lib/lib.es2015.symbol.wellknown.d.ts +++ b/lib/lib.es2015.symbol.wellknown.d.ts @@ -135,7 +135,7 @@ interface Map { readonly [Symbol.toStringTag]: string; } -interface WeakMap { +interface WeakMap { readonly [Symbol.toStringTag]: string; } @@ -143,7 +143,7 @@ interface Set { readonly [Symbol.toStringTag]: string; } -interface WeakSet { +interface WeakSet { readonly [Symbol.toStringTag]: string; } diff --git a/lib/lib.es2021.weakref.d.ts b/lib/lib.es2021.weakref.d.ts index 6f67efd50315c..01ba9363c5480 100644 --- a/lib/lib.es2021.weakref.d.ts +++ b/lib/lib.es2021.weakref.d.ts @@ -17,7 +17,7 @@ and limitations under the License. /// -interface WeakRef { +interface WeakRef { readonly [Symbol.toStringTag]: "WeakRef"; /** @@ -34,7 +34,7 @@ interface WeakRefConstructor { * Creates a WeakRef instance for the given target object. * @param target The target object for the WeakRef instance. */ - new(target: T): WeakRef; + new(target: T): WeakRef; } declare var WeakRef: WeakRefConstructor; @@ -51,7 +51,7 @@ interface FinalizationRegistry { * object. If provided (and not undefined), this must be an object. If not provided, the target * cannot be unregistered. */ - register(target: symbol, heldValue: T, unregisterToken?: symbol): void; + register(target: object, heldValue: T, unregisterToken?: object): void; /** * Unregisters an object from the registry. From 18ec290e15e6de05fe09872d5de8bd8d11c3ede2 Mon Sep 17 00:00:00 2001 From: Leo Elmecker Date: Thu, 23 Mar 2023 00:19:37 +0000 Subject: [PATCH 09/24] Undo lib changes --- lib/lib.es2021.weakref.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/lib.es2021.weakref.d.ts b/lib/lib.es2021.weakref.d.ts index 01ba9363c5480..eb7764242d7b9 100644 --- a/lib/lib.es2021.weakref.d.ts +++ b/lib/lib.es2021.weakref.d.ts @@ -17,6 +17,7 @@ and limitations under the License. /// + interface WeakRef { readonly [Symbol.toStringTag]: "WeakRef"; From 01986578adfa284e38ce1592e9e5e053e1f71eb9 Mon Sep 17 00:00:00 2001 From: Leo Elmecker Date: Wed, 29 Mar 2023 23:25:29 +0100 Subject: [PATCH 10/24] Address PR comments --- src/compiler/commandLineParser.ts | 4 ++-- src/lib/es2015.collection.d.ts | 14 +++++++------- src/lib/es2015.iterable.d.ts | 8 ++++---- src/lib/es2015.symbol.wellknown.d.ts | 4 ++-- src/lib/es2021.weakref.d.ts | 4 ++-- src/lib/es2023.collection.d.ts | 12 ++++++------ src/lib/es2023.weakref.d.ts | 6 +++--- 7 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 1343e9d461b76..cf7383cbe2cc1 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -214,8 +214,8 @@ const libEntries: [string, string][] = [ ["es2023.collection", "lib.es2023.collection.d.ts"], ["es2023.weakref", "lib.es2023.weakref.d.ts"], ["esnext.array", "lib.es2023.array.d.ts"], - ["esnext.array", "lib.es2023.collection.d.ts"], - ["esnext.array", "lib.es2023.weakref.d.ts"], + ["esnext.collection", "lib.es2023.collection.d.ts"], + ["esnext.weakref", "lib.es2023.weakref.d.ts"], ["esnext.symbol", "lib.es2019.symbol.d.ts"], ["esnext.asynciterable", "lib.es2018.asynciterable.d.ts"], ["esnext.intl", "lib.esnext.intl.d.ts"], diff --git a/src/lib/es2015.collection.d.ts b/src/lib/es2015.collection.d.ts index 3ab7175543949..9a84882fbf89d 100644 --- a/src/lib/es2015.collection.d.ts +++ b/src/lib/es2015.collection.d.ts @@ -42,13 +42,13 @@ interface ReadonlyMap { readonly size: number; } -type WeakKeyTypes = WeakKeyTypesStore[keyof WeakKeyTypesStore]; - -interface WeakKeyTypesStore { +interface WeakKeyTypes { object: object; } -interface WeakMap { +type WeakKey = WeakKeyTypes[keyof WeakKeyTypes]; + +interface WeakMap { /** * Removes the specified element from the WeakMap. * @returns true if the element was successfully removed, or false if it was not present. @@ -113,7 +113,7 @@ interface ReadonlySet { readonly size: number; } -interface WeakSet { +interface WeakSet { /** * Appends a new object to the end of the WeakSet. */ @@ -130,7 +130,7 @@ interface WeakSet { } interface WeakSetConstructor { - new (values?: readonly T[] | null): WeakSet; - readonly prototype: WeakSet; + new (values?: readonly T[] | null): WeakSet; + readonly prototype: WeakSet; } declare var WeakSet: WeakSetConstructor; diff --git a/src/lib/es2015.iterable.d.ts b/src/lib/es2015.iterable.d.ts index ac5fe27670c78..c7b7afa72119d 100644 --- a/src/lib/es2015.iterable.d.ts +++ b/src/lib/es2015.iterable.d.ts @@ -141,10 +141,10 @@ interface MapConstructor { new (iterable?: Iterable | null): Map; } -interface WeakMap { } +interface WeakMap { } interface WeakMapConstructor { - new (iterable: Iterable): WeakMap; + new (iterable: Iterable): WeakMap; } interface Set { @@ -189,10 +189,10 @@ interface SetConstructor { new (iterable?: Iterable | null): Set; } -interface WeakSet { } +interface WeakSet { } interface WeakSetConstructor { - new (iterable: Iterable): WeakSet; + new (iterable: Iterable): WeakSet; } interface Promise { } diff --git a/src/lib/es2015.symbol.wellknown.d.ts b/src/lib/es2015.symbol.wellknown.d.ts index 643f402ea62b6..51134ff07dbfa 100644 --- a/src/lib/es2015.symbol.wellknown.d.ts +++ b/src/lib/es2015.symbol.wellknown.d.ts @@ -115,7 +115,7 @@ interface Map { readonly [Symbol.toStringTag]: string; } -interface WeakMap { +interface WeakMap { readonly [Symbol.toStringTag]: string; } @@ -123,7 +123,7 @@ interface Set { readonly [Symbol.toStringTag]: string; } -interface WeakSet { +interface WeakSet { readonly [Symbol.toStringTag]: string; } diff --git a/src/lib/es2021.weakref.d.ts b/src/lib/es2021.weakref.d.ts index aa8345e2d5886..4c55a26f99303 100644 --- a/src/lib/es2021.weakref.d.ts +++ b/src/lib/es2021.weakref.d.ts @@ -1,4 +1,4 @@ -interface WeakRef { +interface WeakRef { readonly [Symbol.toStringTag]: "WeakRef"; /** @@ -15,7 +15,7 @@ interface WeakRefConstructor { * Creates a WeakRef instance for the given target object. * @param target The target object for the WeakRef instance. */ - new(target: T): WeakRef; + new(target: T): WeakRef; } declare var WeakRef: WeakRefConstructor; diff --git a/src/lib/es2023.collection.d.ts b/src/lib/es2023.collection.d.ts index cfc69183956fe..ad3c66e6ca932 100644 --- a/src/lib/es2023.collection.d.ts +++ b/src/lib/es2023.collection.d.ts @@ -1,16 +1,16 @@ -interface WeakKeyTypesStore { +interface WeakKeyTypes { symbol: symbol; } -interface WeakSet {} +interface WeakSet {} interface WeakSetConstructor { - new (values?: readonly T[] | null): WeakSet; + new (values?: readonly T[] | null): WeakSet; } -interface WeakMap {} +interface WeakMap {} interface WeakMapConstructor { - new (entries?: readonly [K, V][] | null): WeakMap; - readonly prototype: WeakMap; + new (entries?: readonly [K, V][] | null): WeakMap; + readonly prototype: WeakMap; } \ No newline at end of file diff --git a/src/lib/es2023.weakref.d.ts b/src/lib/es2023.weakref.d.ts index 609dda30b3349..ce11d9b02157d 100644 --- a/src/lib/es2023.weakref.d.ts +++ b/src/lib/es2023.weakref.d.ts @@ -1,4 +1,4 @@ -interface WeakKeyTypesStore { +interface WeakKeyTypes { symbol: symbol; } @@ -36,7 +36,7 @@ interface FinalizationRegistryConstructor { declare var FinalizationRegistry: FinalizationRegistryConstructor; -interface WeakRef { +interface WeakRef { /** * Returns the WeakRef instance's target object, or undefined if the target object has been * reclaimed. @@ -45,5 +45,5 @@ interface WeakRef { } interface WeakRefConstructor { - new(target: T): WeakRef; + new(target: T): WeakRef; } \ No newline at end of file From a103a0b76ead4d709a24312f1d6d79e5aa01cd2c Mon Sep 17 00:00:00 2001 From: Leo Elmecker Date: Thu, 9 Feb 2023 16:17:24 +0000 Subject: [PATCH 11/24] Update 2021 weakref types Signed-off-by: Leo Elmecker --- lib/lib.es2021.weakref.d.ts | 9 +++++++-- src/lib/es2021.weakref.d.ts | 4 ++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/lib.es2021.weakref.d.ts b/lib/lib.es2021.weakref.d.ts index eb7764242d7b9..415ee6af8e392 100644 --- a/lib/lib.es2021.weakref.d.ts +++ b/lib/lib.es2021.weakref.d.ts @@ -17,8 +17,13 @@ and limitations under the License. /// +type AllowedWeakTypes = AllowedWeakTypesStore[keyof AllowedWeakTypesStore]; -interface WeakRef { +interface AllowedWeakTypesStore { + object: object; +} + +interface WeakRef { readonly [Symbol.toStringTag]: "WeakRef"; /** @@ -35,7 +40,7 @@ interface WeakRefConstructor { * Creates a WeakRef instance for the given target object. * @param target The target object for the WeakRef instance. */ - new(target: T): WeakRef; + new(target: T): WeakRef; } declare var WeakRef: WeakRefConstructor; diff --git a/src/lib/es2021.weakref.d.ts b/src/lib/es2021.weakref.d.ts index d36ddb6a19cfd..7ab112f32cf58 100644 --- a/src/lib/es2021.weakref.d.ts +++ b/src/lib/es2021.weakref.d.ts @@ -1,4 +1,4 @@ -interface WeakRef { +interface WeakRef { readonly [Symbol.toStringTag]: "WeakRef"; /** @@ -15,7 +15,7 @@ interface WeakRefConstructor { * Creates a WeakRef instance for the given target object. * @param target The target object for the WeakRef instance. */ - new(target: T): WeakRef; + new(target: T): WeakRef; } declare var WeakRef: WeakRefConstructor; From e898ad0d55d8769848eca39240946df2891ad7cb Mon Sep 17 00:00:00 2001 From: Leo Elmecker Date: Thu, 9 Feb 2023 16:17:51 +0000 Subject: [PATCH 12/24] Add symbol to WeakRef and FinalizationRegistry Signed-off-by: Leo Elmecker --- src/lib/es2023.collection.d.ts | 7 +++++++ src/lib/es2023.weakref.d.ts | 20 ++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 src/lib/es2023.collection.d.ts create mode 100644 src/lib/es2023.weakref.d.ts diff --git a/src/lib/es2023.collection.d.ts b/src/lib/es2023.collection.d.ts new file mode 100644 index 0000000000000..b03c2cde4ef8d --- /dev/null +++ b/src/lib/es2023.collection.d.ts @@ -0,0 +1,7 @@ +interface WeakMapConstructor { + new (entries?: readonly [K, V][] | null): WeakMap; +} + +interface WeakSetConstructor { + new (values?: readonly T[] | null): WeakSet; +} \ No newline at end of file diff --git a/src/lib/es2023.weakref.d.ts b/src/lib/es2023.weakref.d.ts new file mode 100644 index 0000000000000..e8ab6648e8c01 --- /dev/null +++ b/src/lib/es2023.weakref.d.ts @@ -0,0 +1,20 @@ +interface AllowedWeakTypesStore { + symbol: symbol; +} + +interface FinalizationRegistry { + register(target: symbol, heldValue: T, unregisterToken?: symbol): void + unregister(unregisterToken: symbol): void; +} + +interface WeakRef { + /** + * Returns the WeakRef instance's target object, or undefined if the target object has been + * reclaimed. + */ + deref(): T | undefined; +} + +interface WeakRefConstructor { + new(target: T): WeakRef; +} \ No newline at end of file From 8b90d0a4fdd09d4e224098834dd796ac4298a2ae Mon Sep 17 00:00:00 2001 From: Leo Elmecker Date: Sun, 5 Mar 2023 23:16:53 +0000 Subject: [PATCH 13/24] Update WeakSet keys Signed-off-by: Leo Elmecker --- lib/lib.es2015.collection.d.ts | 12 +++++++++--- lib/lib.es2015.iterable.d.ts | 4 ++-- lib/lib.es2015.symbol.wellknown.d.ts | 2 +- lib/lib.es2021.weakref.d.ts | 8 ++++---- src/lib/es2015.collection.d.ts | 6 +++--- src/lib/es2015.iterable.d.ts | 4 ++-- src/lib/es2015.symbol.wellknown.d.ts | 2 +- src/lib/es2021.weakref.d.ts | 4 ++-- src/lib/es2023.collection.d.ts | 6 +++--- src/lib/es2023.weakref.d.ts | 6 +++--- tests/cases/compiler/forwardDeclaredCommonTypes01.ts | 2 +- 11 files changed, 31 insertions(+), 25 deletions(-) diff --git a/lib/lib.es2015.collection.d.ts b/lib/lib.es2015.collection.d.ts index c2e7733ae54b4..10a4a0a7bf0d8 100644 --- a/lib/lib.es2015.collection.d.ts +++ b/lib/lib.es2015.collection.d.ts @@ -127,7 +127,13 @@ interface ReadonlySet { readonly size: number; } -interface WeakSet { +type WeakKeyTypes = WeakKeyTypesStore[keyof WeakKeyTypesStore]; + +interface WeakKeyTypesStore { + object: object; +} + +interface WeakSet { /** * Appends a new object to the end of the WeakSet. */ @@ -144,7 +150,7 @@ interface WeakSet { } interface WeakSetConstructor { - new (values?: readonly T[] | null): WeakSet; - readonly prototype: WeakSet; + new (values?: readonly T[] | null): WeakSet; + readonly prototype: WeakSet; } declare var WeakSet: WeakSetConstructor; diff --git a/lib/lib.es2015.iterable.d.ts b/lib/lib.es2015.iterable.d.ts index 8a7292383442d..0e7ea95e16fa0 100644 --- a/lib/lib.es2015.iterable.d.ts +++ b/lib/lib.es2015.iterable.d.ts @@ -209,10 +209,10 @@ interface SetConstructor { new (iterable?: Iterable | null): Set; } -interface WeakSet { } +interface WeakSet { } interface WeakSetConstructor { - new (iterable: Iterable): WeakSet; + new (iterable: Iterable): WeakSet; } interface Promise { } diff --git a/lib/lib.es2015.symbol.wellknown.d.ts b/lib/lib.es2015.symbol.wellknown.d.ts index 81e052bf26d27..e311fe7492d7f 100644 --- a/lib/lib.es2015.symbol.wellknown.d.ts +++ b/lib/lib.es2015.symbol.wellknown.d.ts @@ -143,7 +143,7 @@ interface Set { readonly [Symbol.toStringTag]: string; } -interface WeakSet { +interface WeakSet { readonly [Symbol.toStringTag]: string; } diff --git a/lib/lib.es2021.weakref.d.ts b/lib/lib.es2021.weakref.d.ts index 415ee6af8e392..b9f9aeed3378c 100644 --- a/lib/lib.es2021.weakref.d.ts +++ b/lib/lib.es2021.weakref.d.ts @@ -17,13 +17,13 @@ and limitations under the License. /// -type AllowedWeakTypes = AllowedWeakTypesStore[keyof AllowedWeakTypesStore]; +type WeakKeyTypes = WeakKeyTypesStore[keyof WeakKeyTypesStore]; -interface AllowedWeakTypesStore { +interface WeakKeyTypesStore { object: object; } -interface WeakRef { +interface WeakRef { readonly [Symbol.toStringTag]: "WeakRef"; /** @@ -40,7 +40,7 @@ interface WeakRefConstructor { * Creates a WeakRef instance for the given target object. * @param target The target object for the WeakRef instance. */ - new(target: T): WeakRef; + new(target: T): WeakRef; } declare var WeakRef: WeakRefConstructor; diff --git a/src/lib/es2015.collection.d.ts b/src/lib/es2015.collection.d.ts index 9e27045a5592a..a6f03fa2963b2 100644 --- a/src/lib/es2015.collection.d.ts +++ b/src/lib/es2015.collection.d.ts @@ -107,7 +107,7 @@ interface ReadonlySet { readonly size: number; } -interface WeakSet { +interface WeakSet { /** * Appends a new object to the end of the WeakSet. */ @@ -124,7 +124,7 @@ interface WeakSet { } interface WeakSetConstructor { - new (values?: readonly T[] | null): WeakSet; - readonly prototype: WeakSet; + new (values?: readonly T[] | null): WeakSet; + readonly prototype: WeakSet; } declare var WeakSet: WeakSetConstructor; diff --git a/src/lib/es2015.iterable.d.ts b/src/lib/es2015.iterable.d.ts index f1fb454f980b1..31d5e10382fa7 100644 --- a/src/lib/es2015.iterable.d.ts +++ b/src/lib/es2015.iterable.d.ts @@ -189,10 +189,10 @@ interface SetConstructor { new (iterable?: Iterable | null): Set; } -interface WeakSet { } +interface WeakSet { } interface WeakSetConstructor { - new (iterable: Iterable): WeakSet; + new (iterable: Iterable): WeakSet; } interface Promise { } diff --git a/src/lib/es2015.symbol.wellknown.d.ts b/src/lib/es2015.symbol.wellknown.d.ts index f27dc68850016..72a830fbb383e 100644 --- a/src/lib/es2015.symbol.wellknown.d.ts +++ b/src/lib/es2015.symbol.wellknown.d.ts @@ -123,7 +123,7 @@ interface Set { readonly [Symbol.toStringTag]: string; } -interface WeakSet { +interface WeakSet { readonly [Symbol.toStringTag]: string; } diff --git a/src/lib/es2021.weakref.d.ts b/src/lib/es2021.weakref.d.ts index 7ab112f32cf58..aa8345e2d5886 100644 --- a/src/lib/es2021.weakref.d.ts +++ b/src/lib/es2021.weakref.d.ts @@ -1,4 +1,4 @@ -interface WeakRef { +interface WeakRef { readonly [Symbol.toStringTag]: "WeakRef"; /** @@ -15,7 +15,7 @@ interface WeakRefConstructor { * Creates a WeakRef instance for the given target object. * @param target The target object for the WeakRef instance. */ - new(target: T): WeakRef; + new(target: T): WeakRef; } declare var WeakRef: WeakRefConstructor; diff --git a/src/lib/es2023.collection.d.ts b/src/lib/es2023.collection.d.ts index b03c2cde4ef8d..4a2868b49bb24 100644 --- a/src/lib/es2023.collection.d.ts +++ b/src/lib/es2023.collection.d.ts @@ -1,7 +1,7 @@ -interface WeakMapConstructor { - new (entries?: readonly [K, V][] | null): WeakMap; +interface WeakSet { + } interface WeakSetConstructor { - new (values?: readonly T[] | null): WeakSet; + new (values?: readonly T[] | null): WeakSet; } \ No newline at end of file diff --git a/src/lib/es2023.weakref.d.ts b/src/lib/es2023.weakref.d.ts index e8ab6648e8c01..e9d00199da909 100644 --- a/src/lib/es2023.weakref.d.ts +++ b/src/lib/es2023.weakref.d.ts @@ -1,4 +1,4 @@ -interface AllowedWeakTypesStore { +interface WeakKeyTypesStore { symbol: symbol; } @@ -7,7 +7,7 @@ interface FinalizationRegistry { unregister(unregisterToken: symbol): void; } -interface WeakRef { +interface WeakRef { /** * Returns the WeakRef instance's target object, or undefined if the target object has been * reclaimed. @@ -16,5 +16,5 @@ interface WeakRef { } interface WeakRefConstructor { - new(target: T): WeakRef; + new(target: T): WeakRef; } \ No newline at end of file diff --git a/tests/cases/compiler/forwardDeclaredCommonTypes01.ts b/tests/cases/compiler/forwardDeclaredCommonTypes01.ts index f4eea80ab0339..931e67ea8de85 100644 --- a/tests/cases/compiler/forwardDeclaredCommonTypes01.ts +++ b/tests/cases/compiler/forwardDeclaredCommonTypes01.ts @@ -6,7 +6,7 @@ interface Symbol {} interface Map {} interface WeakMap {} interface Set {} -interface WeakSet {} +interface WeakSet {} (function() { new Promise; From 485aea5b7c9e5911e1568409ed6537d4ba0f9ad9 Mon Sep 17 00:00:00 2001 From: Leo Elmecker Date: Sun, 5 Mar 2023 23:26:01 +0000 Subject: [PATCH 14/24] Add WeakMap symbol support Signed-off-by: Leo Elmecker --- lib/lib.es2015.collection.d.ts | 6 ++-- lib/lib.es2015.iterable.d.ts | 4 +-- lib/lib.es2015.symbol.wellknown.d.ts | 2 +- src/lib/es2015.collection.d.ts | 2 +- src/lib/es2015.iterable.d.ts | 4 +-- src/lib/es2015.symbol.wellknown.d.ts | 2 +- src/lib/es2023.collection.d.ts | 13 ++++++-- .../reference/forwardDeclaredCommonTypes01.js | 30 +++++++++---------- .../compiler/forwardDeclaredCommonTypes01.ts | 2 +- 9 files changed, 37 insertions(+), 28 deletions(-) diff --git a/lib/lib.es2015.collection.d.ts b/lib/lib.es2015.collection.d.ts index 10a4a0a7bf0d8..ab842750c3984 100644 --- a/lib/lib.es2015.collection.d.ts +++ b/lib/lib.es2015.collection.d.ts @@ -62,7 +62,7 @@ interface ReadonlyMap { readonly size: number; } -interface WeakMap { +interface WeakMap { /** * Removes the specified element from the WeakMap. * @returns true if the element was successfully removed, or false if it was not present. @@ -84,8 +84,8 @@ interface WeakMap { } interface WeakMapConstructor { - new (entries?: readonly [K, V][] | null): WeakMap; - readonly prototype: WeakMap; + new (entries?: readonly [K, V][] | null): WeakMap; + readonly prototype: WeakMap; } declare var WeakMap: WeakMapConstructor; diff --git a/lib/lib.es2015.iterable.d.ts b/lib/lib.es2015.iterable.d.ts index 0e7ea95e16fa0..fecd3024f366c 100644 --- a/lib/lib.es2015.iterable.d.ts +++ b/lib/lib.es2015.iterable.d.ts @@ -161,10 +161,10 @@ interface MapConstructor { new (iterable?: Iterable | null): Map; } -interface WeakMap { } +interface WeakMap { } interface WeakMapConstructor { - new (iterable: Iterable): WeakMap; + new (iterable: Iterable): WeakMap; } interface Set { diff --git a/lib/lib.es2015.symbol.wellknown.d.ts b/lib/lib.es2015.symbol.wellknown.d.ts index e311fe7492d7f..13b265343321b 100644 --- a/lib/lib.es2015.symbol.wellknown.d.ts +++ b/lib/lib.es2015.symbol.wellknown.d.ts @@ -135,7 +135,7 @@ interface Map { readonly [Symbol.toStringTag]: string; } -interface WeakMap { +interface WeakMap { readonly [Symbol.toStringTag]: string; } diff --git a/src/lib/es2015.collection.d.ts b/src/lib/es2015.collection.d.ts index a6f03fa2963b2..ecb4f27cbd881 100644 --- a/src/lib/es2015.collection.d.ts +++ b/src/lib/es2015.collection.d.ts @@ -42,7 +42,7 @@ interface ReadonlyMap { readonly size: number; } -interface WeakMap { +interface WeakMap { /** * Removes the specified element from the WeakMap. * @returns true if the element was successfully removed, or false if it was not present. diff --git a/src/lib/es2015.iterable.d.ts b/src/lib/es2015.iterable.d.ts index 31d5e10382fa7..ac5fe27670c78 100644 --- a/src/lib/es2015.iterable.d.ts +++ b/src/lib/es2015.iterable.d.ts @@ -141,10 +141,10 @@ interface MapConstructor { new (iterable?: Iterable | null): Map; } -interface WeakMap { } +interface WeakMap { } interface WeakMapConstructor { - new (iterable: Iterable): WeakMap; + new (iterable: Iterable): WeakMap; } interface Set { diff --git a/src/lib/es2015.symbol.wellknown.d.ts b/src/lib/es2015.symbol.wellknown.d.ts index 72a830fbb383e..643f402ea62b6 100644 --- a/src/lib/es2015.symbol.wellknown.d.ts +++ b/src/lib/es2015.symbol.wellknown.d.ts @@ -115,7 +115,7 @@ interface Map { readonly [Symbol.toStringTag]: string; } -interface WeakMap { +interface WeakMap { readonly [Symbol.toStringTag]: string; } diff --git a/src/lib/es2023.collection.d.ts b/src/lib/es2023.collection.d.ts index 4a2868b49bb24..cfc69183956fe 100644 --- a/src/lib/es2023.collection.d.ts +++ b/src/lib/es2023.collection.d.ts @@ -1,7 +1,16 @@ -interface WeakSet { - +interface WeakKeyTypesStore { + symbol: symbol; } +interface WeakSet {} + interface WeakSetConstructor { new (values?: readonly T[] | null): WeakSet; +} + +interface WeakMap {} + +interface WeakMapConstructor { + new (entries?: readonly [K, V][] | null): WeakMap; + readonly prototype: WeakMap; } \ No newline at end of file diff --git a/tests/baselines/reference/forwardDeclaredCommonTypes01.js b/tests/baselines/reference/forwardDeclaredCommonTypes01.js index 5177852443034..83743b2f3a2a4 100644 --- a/tests/baselines/reference/forwardDeclaredCommonTypes01.js +++ b/tests/baselines/reference/forwardDeclaredCommonTypes01.js @@ -1,10 +1,10 @@ -//// [forwardDeclaredCommonTypes01.ts] +//// [forwardDeclaredCommonTypes01.ts] interface Promise {} interface Symbol {} interface Map {} -interface WeakMap {} +interface WeakMap {} interface Set {} -interface WeakSet {} +interface WeakSet {} (function() { new Promise; @@ -14,15 +14,15 @@ interface WeakSet {} new Set; new WeakSet; }); - - -//// [forwardDeclaredCommonTypes01.js] -(function () { - new Promise; - new Symbol; - Symbol(); - new Map; - new WeakMap; - new Set; - new WeakSet; -}); + + +//// [forwardDeclaredCommonTypes01.js] +(function () { + new Promise; + new Symbol; + Symbol(); + new Map; + new WeakMap; + new Set; + new WeakSet; +}); diff --git a/tests/cases/compiler/forwardDeclaredCommonTypes01.ts b/tests/cases/compiler/forwardDeclaredCommonTypes01.ts index 931e67ea8de85..b9e69f1383b4b 100644 --- a/tests/cases/compiler/forwardDeclaredCommonTypes01.ts +++ b/tests/cases/compiler/forwardDeclaredCommonTypes01.ts @@ -4,7 +4,7 @@ interface Promise {} interface Symbol {} interface Map {} -interface WeakMap {} +interface WeakMap {} interface Set {} interface WeakSet {} From 63506173390b1e1d80527552a9418e01e43ca7aa Mon Sep 17 00:00:00 2001 From: Leo Elmecker Date: Tue, 14 Mar 2023 18:34:37 +0000 Subject: [PATCH 15/24] Resolve compilation and testing issues Signed-off-by: Leo Elmecker --- src/compiler/commandLineParser.ts | 2 ++ src/lib/es2015.collection.d.ts | 6 ++++ src/lib/es2023.d.ts | 1 + src/lib/libs.json | 1 + .../reference/acceptSymbolAsWeakType.js | 10 ++++++ .../dissallowSymbolAsWeakType.errors.txt | 31 +++++++++++++++++++ .../reference/dissallowSymbolAsWeakType.js | 10 ++++++ .../reference/forwardDeclaredCommonTypes01.js | 30 +++++++++--------- .../cases/compiler/acceptSymbolAsWeakType.ts | 7 +++++ .../compiler/dissallowSymbolAsWeakType.ts | 7 +++++ .../compiler/forwardDeclaredCommonTypes01.ts | 4 +-- 11 files changed, 92 insertions(+), 17 deletions(-) create mode 100644 tests/baselines/reference/acceptSymbolAsWeakType.js create mode 100644 tests/baselines/reference/dissallowSymbolAsWeakType.errors.txt create mode 100644 tests/baselines/reference/dissallowSymbolAsWeakType.js create mode 100644 tests/cases/compiler/acceptSymbolAsWeakType.ts create mode 100644 tests/cases/compiler/dissallowSymbolAsWeakType.ts diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 629063de29808..1f0ff1362421d 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -211,7 +211,9 @@ const libEntries: [string, string][] = [ ["es2022.string", "lib.es2022.string.d.ts"], ["es2022.regexp", "lib.es2022.regexp.d.ts"], ["es2023.array", "lib.es2023.array.d.ts"], + ["es2023.collection", "lib.es2023.collection.d.ts"], ["esnext.array", "lib.es2023.array.d.ts"], + ["esnext.array", "lib.es2023.collection.d.ts"], ["esnext.symbol", "lib.es2019.symbol.d.ts"], ["esnext.asynciterable", "lib.es2018.asynciterable.d.ts"], ["esnext.intl", "lib.esnext.intl.d.ts"], diff --git a/src/lib/es2015.collection.d.ts b/src/lib/es2015.collection.d.ts index ecb4f27cbd881..3ab7175543949 100644 --- a/src/lib/es2015.collection.d.ts +++ b/src/lib/es2015.collection.d.ts @@ -42,6 +42,12 @@ interface ReadonlyMap { readonly size: number; } +type WeakKeyTypes = WeakKeyTypesStore[keyof WeakKeyTypesStore]; + +interface WeakKeyTypesStore { + object: object; +} + interface WeakMap { /** * Removes the specified element from the WeakMap. diff --git a/src/lib/es2023.d.ts b/src/lib/es2023.d.ts index 02292dc39546f..5c45f807e08a8 100644 --- a/src/lib/es2023.d.ts +++ b/src/lib/es2023.d.ts @@ -1,2 +1,3 @@ /// /// +/// diff --git a/src/lib/libs.json b/src/lib/libs.json index 82ba97aa35fb8..5613674ef77d5 100644 --- a/src/lib/libs.json +++ b/src/lib/libs.json @@ -65,6 +65,7 @@ "es2022.string", "es2022.regexp", "es2023.array", + "es2023.collection", "esnext.intl", "decorators", "decorators.legacy", diff --git a/tests/baselines/reference/acceptSymbolAsWeakType.js b/tests/baselines/reference/acceptSymbolAsWeakType.js new file mode 100644 index 0000000000000..d855204aa12c7 --- /dev/null +++ b/tests/baselines/reference/acceptSymbolAsWeakType.js @@ -0,0 +1,10 @@ +//// [acceptSymbolAsWeakType.ts] +const s: symbol = Symbol('s'); + +const ws = new WeakSet([s]); +ws.add(s); + +//// [acceptSymbolAsWeakType.js] +const s = Symbol('s'); +const ws = new WeakSet([s]); +ws.add(s); diff --git a/tests/baselines/reference/dissallowSymbolAsWeakType.errors.txt b/tests/baselines/reference/dissallowSymbolAsWeakType.errors.txt new file mode 100644 index 0000000000000..7d17aeaf5d614 --- /dev/null +++ b/tests/baselines/reference/dissallowSymbolAsWeakType.errors.txt @@ -0,0 +1,31 @@ +tests/cases/compiler/dissallowSymbolAsWeakType.ts(3,12): error TS2769: No overload matches this call. + Overload 1 of 2, '(iterable: Iterable): WeakSet', gave the following error. + Argument of type 'symbol[]' is not assignable to parameter of type 'Iterable'. + The types returned by '[Symbol.iterator]().next(...)' are incompatible between these types. + Type 'IteratorResult' is not assignable to type 'IteratorResult'. + Type 'IteratorYieldResult' is not assignable to type 'IteratorResult'. + Type 'IteratorYieldResult' is not assignable to type 'IteratorYieldResult'. + Type 'symbol' is not assignable to type 'object'. + Overload 2 of 2, '(values?: readonly object[]): WeakSet', gave the following error. + Type 'symbol' is not assignable to type 'object'. +tests/cases/compiler/dissallowSymbolAsWeakType.ts(4,8): error TS2345: Argument of type 'symbol' is not assignable to parameter of type 'object'. + + +==== tests/cases/compiler/dissallowSymbolAsWeakType.ts (2 errors) ==== + const s: symbol = Symbol('s'); + + const ws = new WeakSet([s]); + ~~~~~~~~~~~~~~~~ +!!! error TS2769: No overload matches this call. +!!! error TS2769: Overload 1 of 2, '(iterable: Iterable): WeakSet', gave the following error. +!!! error TS2769: Argument of type 'symbol[]' is not assignable to parameter of type 'Iterable'. +!!! error TS2769: The types returned by '[Symbol.iterator]().next(...)' are incompatible between these types. +!!! error TS2769: Type 'IteratorResult' is not assignable to type 'IteratorResult'. +!!! error TS2769: Type 'IteratorYieldResult' is not assignable to type 'IteratorResult'. +!!! error TS2769: Type 'IteratorYieldResult' is not assignable to type 'IteratorYieldResult'. +!!! error TS2769: Type 'symbol' is not assignable to type 'object'. +!!! error TS2769: Overload 2 of 2, '(values?: readonly object[]): WeakSet', gave the following error. +!!! error TS2769: Type 'symbol' is not assignable to type 'object'. + ws.add(s); + ~ +!!! error TS2345: Argument of type 'symbol' is not assignable to parameter of type 'object'. \ No newline at end of file diff --git a/tests/baselines/reference/dissallowSymbolAsWeakType.js b/tests/baselines/reference/dissallowSymbolAsWeakType.js new file mode 100644 index 0000000000000..a670ac34b2bd3 --- /dev/null +++ b/tests/baselines/reference/dissallowSymbolAsWeakType.js @@ -0,0 +1,10 @@ +//// [dissallowSymbolAsWeakType.ts] +const s: symbol = Symbol('s'); + +const ws = new WeakSet([s]); +ws.add(s); + +//// [dissallowSymbolAsWeakType.js] +const s = Symbol('s'); +const ws = new WeakSet([s]); +ws.add(s); diff --git a/tests/baselines/reference/forwardDeclaredCommonTypes01.js b/tests/baselines/reference/forwardDeclaredCommonTypes01.js index 83743b2f3a2a4..5177852443034 100644 --- a/tests/baselines/reference/forwardDeclaredCommonTypes01.js +++ b/tests/baselines/reference/forwardDeclaredCommonTypes01.js @@ -1,10 +1,10 @@ -//// [forwardDeclaredCommonTypes01.ts] +//// [forwardDeclaredCommonTypes01.ts] interface Promise {} interface Symbol {} interface Map {} -interface WeakMap {} +interface WeakMap {} interface Set {} -interface WeakSet {} +interface WeakSet {} (function() { new Promise; @@ -14,15 +14,15 @@ interface WeakSet {} new Set; new WeakSet; }); - - -//// [forwardDeclaredCommonTypes01.js] -(function () { - new Promise; - new Symbol; - Symbol(); - new Map; - new WeakMap; - new Set; - new WeakSet; -}); + + +//// [forwardDeclaredCommonTypes01.js] +(function () { + new Promise; + new Symbol; + Symbol(); + new Map; + new WeakMap; + new Set; + new WeakSet; +}); diff --git a/tests/cases/compiler/acceptSymbolAsWeakType.ts b/tests/cases/compiler/acceptSymbolAsWeakType.ts new file mode 100644 index 0000000000000..5cf02fa473837 --- /dev/null +++ b/tests/cases/compiler/acceptSymbolAsWeakType.ts @@ -0,0 +1,7 @@ +// @lib: esnext +// @target: esnext + +const s: symbol = Symbol('s'); + +const ws = new WeakSet([s]); +ws.add(s); \ No newline at end of file diff --git a/tests/cases/compiler/dissallowSymbolAsWeakType.ts b/tests/cases/compiler/dissallowSymbolAsWeakType.ts new file mode 100644 index 0000000000000..7b7f98fb7c548 --- /dev/null +++ b/tests/cases/compiler/dissallowSymbolAsWeakType.ts @@ -0,0 +1,7 @@ +// @lib: es2022 +// @target: es2022 + +const s: symbol = Symbol('s'); + +const ws = new WeakSet([s]); +ws.add(s); \ No newline at end of file diff --git a/tests/cases/compiler/forwardDeclaredCommonTypes01.ts b/tests/cases/compiler/forwardDeclaredCommonTypes01.ts index b9e69f1383b4b..f4eea80ab0339 100644 --- a/tests/cases/compiler/forwardDeclaredCommonTypes01.ts +++ b/tests/cases/compiler/forwardDeclaredCommonTypes01.ts @@ -4,9 +4,9 @@ interface Promise {} interface Symbol {} interface Map {} -interface WeakMap {} +interface WeakMap {} interface Set {} -interface WeakSet {} +interface WeakSet {} (function() { new Promise; From b1a8c3790cd9c8abaf92ae6ed66cd6001be26e9c Mon Sep 17 00:00:00 2001 From: Leo Elmecker Date: Thu, 16 Mar 2023 16:55:22 +0000 Subject: [PATCH 16/24] Add some test changes Signed-off-by: Leo Elmecker --- tests/cases/compiler/acceptSymbolAsWeakType.ts | 10 +++++++++- tests/cases/compiler/dissallowSymbolAsWeakType.ts | 10 +++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/tests/cases/compiler/acceptSymbolAsWeakType.ts b/tests/cases/compiler/acceptSymbolAsWeakType.ts index 5cf02fa473837..3c1fc9b6c2068 100644 --- a/tests/cases/compiler/acceptSymbolAsWeakType.ts +++ b/tests/cases/compiler/acceptSymbolAsWeakType.ts @@ -4,4 +4,12 @@ const s: symbol = Symbol('s'); const ws = new WeakSet([s]); -ws.add(s); \ No newline at end of file +ws.add(s); +ws.has(s); +ws.delete(s); + +const wm = new WeakMap([[s, false]]); +wm.set(s, true); +wm.has(s); +wm.get(s); +wm.delete(s); \ No newline at end of file diff --git a/tests/cases/compiler/dissallowSymbolAsWeakType.ts b/tests/cases/compiler/dissallowSymbolAsWeakType.ts index 7b7f98fb7c548..88d27a3c55b8b 100644 --- a/tests/cases/compiler/dissallowSymbolAsWeakType.ts +++ b/tests/cases/compiler/dissallowSymbolAsWeakType.ts @@ -4,4 +4,12 @@ const s: symbol = Symbol('s'); const ws = new WeakSet([s]); -ws.add(s); \ No newline at end of file +ws.add(s); +ws.has(s); +ws.delete(s); + +const wm = new WeakMap([[s, false]]); +wm.set(s, true); +wm.has(s); +wm.get(s); +wm.delete(s); From 841342536ba8cb06f32e31231ed74c724d0024ab Mon Sep 17 00:00:00 2001 From: Leo Elmecker Date: Wed, 22 Mar 2023 23:49:37 +0000 Subject: [PATCH 17/24] Add testing for WeakRef and FinalizationRegistry Signed-off-by: Leo Elmecker --- lib/lib.es2021.weakref.d.ts | 8 +-- src/compiler/commandLineParser.ts | 2 + src/lib/es2023.d.ts | 1 + src/lib/es2023.weakref.d.ts | 33 ++++++++- src/lib/libs.json | 1 + .../reference/acceptSymbolAsWeakType.js | 29 +++++++- .../dissallowSymbolAsWeakType.errors.txt | 72 ++++++++++++++++++- .../reference/dissallowSymbolAsWeakType.js | 30 +++++++- .../cases/compiler/acceptSymbolAsWeakType.ts | 9 ++- .../compiler/dissallowSymbolAsWeakType.ts | 7 ++ 10 files changed, 178 insertions(+), 14 deletions(-) diff --git a/lib/lib.es2021.weakref.d.ts b/lib/lib.es2021.weakref.d.ts index b9f9aeed3378c..6f67efd50315c 100644 --- a/lib/lib.es2021.weakref.d.ts +++ b/lib/lib.es2021.weakref.d.ts @@ -17,12 +17,6 @@ and limitations under the License. /// -type WeakKeyTypes = WeakKeyTypesStore[keyof WeakKeyTypesStore]; - -interface WeakKeyTypesStore { - object: object; -} - interface WeakRef { readonly [Symbol.toStringTag]: "WeakRef"; @@ -57,7 +51,7 @@ interface FinalizationRegistry { * object. If provided (and not undefined), this must be an object. If not provided, the target * cannot be unregistered. */ - register(target: object, heldValue: T, unregisterToken?: object): void; + register(target: symbol, heldValue: T, unregisterToken?: symbol): void; /** * Unregisters an object from the registry. diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 1f0ff1362421d..1343e9d461b76 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -212,8 +212,10 @@ const libEntries: [string, string][] = [ ["es2022.regexp", "lib.es2022.regexp.d.ts"], ["es2023.array", "lib.es2023.array.d.ts"], ["es2023.collection", "lib.es2023.collection.d.ts"], + ["es2023.weakref", "lib.es2023.weakref.d.ts"], ["esnext.array", "lib.es2023.array.d.ts"], ["esnext.array", "lib.es2023.collection.d.ts"], + ["esnext.array", "lib.es2023.weakref.d.ts"], ["esnext.symbol", "lib.es2019.symbol.d.ts"], ["esnext.asynciterable", "lib.es2018.asynciterable.d.ts"], ["esnext.intl", "lib.esnext.intl.d.ts"], diff --git a/src/lib/es2023.d.ts b/src/lib/es2023.d.ts index 5c45f807e08a8..243142c103eda 100644 --- a/src/lib/es2023.d.ts +++ b/src/lib/es2023.d.ts @@ -1,3 +1,4 @@ /// /// /// +/// diff --git a/src/lib/es2023.weakref.d.ts b/src/lib/es2023.weakref.d.ts index e9d00199da909..609dda30b3349 100644 --- a/src/lib/es2023.weakref.d.ts +++ b/src/lib/es2023.weakref.d.ts @@ -3,10 +3,39 @@ interface WeakKeyTypesStore { } interface FinalizationRegistry { - register(target: symbol, heldValue: T, unregisterToken?: symbol): void - unregister(unregisterToken: symbol): void; + readonly [Symbol.toStringTag]: "FinalizationRegistry"; + + /** + * Registers an object with the registry. + * @param target The target object to register. + * @param heldValue The value to pass to the finalizer for this object. This cannot be the + * target object. + * @param unregisterToken The token to pass to the unregister method to unregister the target + * object. If provided (and not undefined), this must be an object. If not provided, the target + * cannot be unregistered. + */ + registerSymbol(target: symbol, heldValue: T, unregisterToken?: symbol): void; + + /** + * Unregisters an object from the registry. + * @param unregisterToken The token that was used as the unregisterToken argument when calling + * register to register the target object. + */ + unregisterSymbol(unregisterToken: symbol): void; } +interface FinalizationRegistryConstructor { + readonly prototype: FinalizationRegistry; + + /** + * Creates a finalization registry with an associated cleanup callback + * @param cleanupCallback The callback to call after an object in the registry has been reclaimed. + */ + new(cleanupCallback: (heldValue: T) => void): FinalizationRegistry; +} + +declare var FinalizationRegistry: FinalizationRegistryConstructor; + interface WeakRef { /** * Returns the WeakRef instance's target object, or undefined if the target object has been diff --git a/src/lib/libs.json b/src/lib/libs.json index 5613674ef77d5..27432a738d42b 100644 --- a/src/lib/libs.json +++ b/src/lib/libs.json @@ -66,6 +66,7 @@ "es2022.regexp", "es2023.array", "es2023.collection", + "es2023.weakref", "esnext.intl", "decorators", "decorators.legacy", diff --git a/tests/baselines/reference/acceptSymbolAsWeakType.js b/tests/baselines/reference/acceptSymbolAsWeakType.js index d855204aa12c7..d562d9cce9157 100644 --- a/tests/baselines/reference/acceptSymbolAsWeakType.js +++ b/tests/baselines/reference/acceptSymbolAsWeakType.js @@ -2,9 +2,36 @@ const s: symbol = Symbol('s'); const ws = new WeakSet([s]); -ws.add(s); +ws.add(s); +ws.has(s); +ws.delete(s); + +const wm = new WeakMap([[s, false]]); +wm.set(s, true); +wm.has(s); +wm.get(s); +wm.delete(s); + +const wr = new WeakRef(s); +wr.deref(); + +const f = new FinalizationRegistry(() => {}); +f.registerSymbol(s, null); +f.unregisterSymbol(s); //// [acceptSymbolAsWeakType.js] const s = Symbol('s'); const ws = new WeakSet([s]); ws.add(s); +ws.has(s); +ws.delete(s); +const wm = new WeakMap([[s, false]]); +wm.set(s, true); +wm.has(s); +wm.get(s); +wm.delete(s); +const wr = new WeakRef(s); +wr.deref(); +const f = new FinalizationRegistry(() => { }); +f.registerSymbol(s, null); +f.unregisterSymbol(s); diff --git a/tests/baselines/reference/dissallowSymbolAsWeakType.errors.txt b/tests/baselines/reference/dissallowSymbolAsWeakType.errors.txt index 7d17aeaf5d614..8f723a128e693 100644 --- a/tests/baselines/reference/dissallowSymbolAsWeakType.errors.txt +++ b/tests/baselines/reference/dissallowSymbolAsWeakType.errors.txt @@ -9,9 +9,30 @@ tests/cases/compiler/dissallowSymbolAsWeakType.ts(3,12): error TS2769: No overlo Overload 2 of 2, '(values?: readonly object[]): WeakSet', gave the following error. Type 'symbol' is not assignable to type 'object'. tests/cases/compiler/dissallowSymbolAsWeakType.ts(4,8): error TS2345: Argument of type 'symbol' is not assignable to parameter of type 'object'. +tests/cases/compiler/dissallowSymbolAsWeakType.ts(5,8): error TS2345: Argument of type 'symbol' is not assignable to parameter of type 'object'. +tests/cases/compiler/dissallowSymbolAsWeakType.ts(6,11): error TS2345: Argument of type 'symbol' is not assignable to parameter of type 'object'. +tests/cases/compiler/dissallowSymbolAsWeakType.ts(8,12): error TS2769: No overload matches this call. + Overload 1 of 2, '(iterable: Iterable): WeakMap', gave the following error. + Argument of type '[symbol, false][]' is not assignable to parameter of type 'Iterable'. + The types returned by '[Symbol.iterator]().next(...)' are incompatible between these types. + Type 'IteratorResult<[symbol, false], any>' is not assignable to type 'IteratorResult'. + Type 'IteratorYieldResult<[symbol, false]>' is not assignable to type 'IteratorResult'. + Type 'IteratorYieldResult<[symbol, false]>' is not assignable to type 'IteratorYieldResult'. + Type '[symbol, false]' is not assignable to type 'readonly [object, boolean]'. + Type at position 0 in source is not compatible with type at position 0 in target. + Type 'symbol' is not assignable to type 'object'. + Overload 2 of 2, '(entries?: readonly [object, boolean][]): WeakMap', gave the following error. + Type 'symbol' is not assignable to type 'object'. +tests/cases/compiler/dissallowSymbolAsWeakType.ts(9,8): error TS2345: Argument of type 'symbol' is not assignable to parameter of type 'object'. +tests/cases/compiler/dissallowSymbolAsWeakType.ts(10,8): error TS2345: Argument of type 'symbol' is not assignable to parameter of type 'object'. +tests/cases/compiler/dissallowSymbolAsWeakType.ts(11,8): error TS2345: Argument of type 'symbol' is not assignable to parameter of type 'object'. +tests/cases/compiler/dissallowSymbolAsWeakType.ts(12,11): error TS2345: Argument of type 'symbol' is not assignable to parameter of type 'object'. +tests/cases/compiler/dissallowSymbolAsWeakType.ts(14,24): error TS2345: Argument of type 'symbol' is not assignable to parameter of type 'object'. +tests/cases/compiler/dissallowSymbolAsWeakType.ts(18,12): error TS2345: Argument of type 'symbol' is not assignable to parameter of type 'object'. +tests/cases/compiler/dissallowSymbolAsWeakType.ts(19,14): error TS2345: Argument of type 'symbol' is not assignable to parameter of type 'object'. -==== tests/cases/compiler/dissallowSymbolAsWeakType.ts (2 errors) ==== +==== tests/cases/compiler/dissallowSymbolAsWeakType.ts (12 errors) ==== const s: symbol = Symbol('s'); const ws = new WeakSet([s]); @@ -28,4 +49,51 @@ tests/cases/compiler/dissallowSymbolAsWeakType.ts(4,8): error TS2345: Argument o !!! error TS2769: Type 'symbol' is not assignable to type 'object'. ws.add(s); ~ -!!! error TS2345: Argument of type 'symbol' is not assignable to parameter of type 'object'. \ No newline at end of file +!!! error TS2345: Argument of type 'symbol' is not assignable to parameter of type 'object'. + ws.has(s); + ~ +!!! error TS2345: Argument of type 'symbol' is not assignable to parameter of type 'object'. + ws.delete(s); + ~ +!!! error TS2345: Argument of type 'symbol' is not assignable to parameter of type 'object'. + + const wm = new WeakMap([[s, false]]); + ~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2769: No overload matches this call. +!!! error TS2769: Overload 1 of 2, '(iterable: Iterable): WeakMap', gave the following error. +!!! error TS2769: Argument of type '[symbol, false][]' is not assignable to parameter of type 'Iterable'. +!!! error TS2769: The types returned by '[Symbol.iterator]().next(...)' are incompatible between these types. +!!! error TS2769: Type 'IteratorResult<[symbol, false], any>' is not assignable to type 'IteratorResult'. +!!! error TS2769: Type 'IteratorYieldResult<[symbol, false]>' is not assignable to type 'IteratorResult'. +!!! error TS2769: Type 'IteratorYieldResult<[symbol, false]>' is not assignable to type 'IteratorYieldResult'. +!!! error TS2769: Type '[symbol, false]' is not assignable to type 'readonly [object, boolean]'. +!!! error TS2769: Type at position 0 in source is not compatible with type at position 0 in target. +!!! error TS2769: Type 'symbol' is not assignable to type 'object'. +!!! error TS2769: Overload 2 of 2, '(entries?: readonly [object, boolean][]): WeakMap', gave the following error. +!!! error TS2769: Type 'symbol' is not assignable to type 'object'. + wm.set(s, true); + ~ +!!! error TS2345: Argument of type 'symbol' is not assignable to parameter of type 'object'. + wm.has(s); + ~ +!!! error TS2345: Argument of type 'symbol' is not assignable to parameter of type 'object'. + wm.get(s); + ~ +!!! error TS2345: Argument of type 'symbol' is not assignable to parameter of type 'object'. + wm.delete(s); + ~ +!!! error TS2345: Argument of type 'symbol' is not assignable to parameter of type 'object'. + + const wr = new WeakRef(s); + ~ +!!! error TS2345: Argument of type 'symbol' is not assignable to parameter of type 'object'. + wr.deref(); + + const f = new FinalizationRegistry(() => {}); + f.register(s, null); + ~ +!!! error TS2345: Argument of type 'symbol' is not assignable to parameter of type 'object'. + f.unregister(s); + ~ +!!! error TS2345: Argument of type 'symbol' is not assignable to parameter of type 'object'. + \ No newline at end of file diff --git a/tests/baselines/reference/dissallowSymbolAsWeakType.js b/tests/baselines/reference/dissallowSymbolAsWeakType.js index a670ac34b2bd3..c9d598f4ee478 100644 --- a/tests/baselines/reference/dissallowSymbolAsWeakType.js +++ b/tests/baselines/reference/dissallowSymbolAsWeakType.js @@ -2,9 +2,37 @@ const s: symbol = Symbol('s'); const ws = new WeakSet([s]); -ws.add(s); +ws.add(s); +ws.has(s); +ws.delete(s); + +const wm = new WeakMap([[s, false]]); +wm.set(s, true); +wm.has(s); +wm.get(s); +wm.delete(s); + +const wr = new WeakRef(s); +wr.deref(); + +const f = new FinalizationRegistry(() => {}); +f.register(s, null); +f.unregister(s); + //// [dissallowSymbolAsWeakType.js] const s = Symbol('s'); const ws = new WeakSet([s]); ws.add(s); +ws.has(s); +ws.delete(s); +const wm = new WeakMap([[s, false]]); +wm.set(s, true); +wm.has(s); +wm.get(s); +wm.delete(s); +const wr = new WeakRef(s); +wr.deref(); +const f = new FinalizationRegistry(() => { }); +f.register(s, null); +f.unregister(s); diff --git a/tests/cases/compiler/acceptSymbolAsWeakType.ts b/tests/cases/compiler/acceptSymbolAsWeakType.ts index 3c1fc9b6c2068..35dc147ac953a 100644 --- a/tests/cases/compiler/acceptSymbolAsWeakType.ts +++ b/tests/cases/compiler/acceptSymbolAsWeakType.ts @@ -12,4 +12,11 @@ const wm = new WeakMap([[s, false]]); wm.set(s, true); wm.has(s); wm.get(s); -wm.delete(s); \ No newline at end of file +wm.delete(s); + +const wr = new WeakRef(s); +wr.deref(); + +const f = new FinalizationRegistry(() => {}); +f.registerSymbol(s, null); +f.unregisterSymbol(s); \ No newline at end of file diff --git a/tests/cases/compiler/dissallowSymbolAsWeakType.ts b/tests/cases/compiler/dissallowSymbolAsWeakType.ts index 88d27a3c55b8b..e6f43b495aead 100644 --- a/tests/cases/compiler/dissallowSymbolAsWeakType.ts +++ b/tests/cases/compiler/dissallowSymbolAsWeakType.ts @@ -13,3 +13,10 @@ wm.set(s, true); wm.has(s); wm.get(s); wm.delete(s); + +const wr = new WeakRef(s); +wr.deref(); + +const f = new FinalizationRegistry(() => {}); +f.register(s, null); +f.unregister(s); From f8470f16d4c8b233cd1831b61cc610770bd4ca12 Mon Sep 17 00:00:00 2001 From: Leo Elmecker Date: Thu, 23 Mar 2023 00:18:36 +0000 Subject: [PATCH 18/24] Undo lib changes Signed-off-by: Leo Elmecker --- lib/lib.es2015.collection.d.ts | 18 ++++++------------ lib/lib.es2015.iterable.d.ts | 8 ++++---- lib/lib.es2015.symbol.wellknown.d.ts | 4 ++-- lib/lib.es2021.weakref.d.ts | 6 +++--- 4 files changed, 15 insertions(+), 21 deletions(-) diff --git a/lib/lib.es2015.collection.d.ts b/lib/lib.es2015.collection.d.ts index ab842750c3984..c2e7733ae54b4 100644 --- a/lib/lib.es2015.collection.d.ts +++ b/lib/lib.es2015.collection.d.ts @@ -62,7 +62,7 @@ interface ReadonlyMap { readonly size: number; } -interface WeakMap { +interface WeakMap { /** * Removes the specified element from the WeakMap. * @returns true if the element was successfully removed, or false if it was not present. @@ -84,8 +84,8 @@ interface WeakMap { } interface WeakMapConstructor { - new (entries?: readonly [K, V][] | null): WeakMap; - readonly prototype: WeakMap; + new (entries?: readonly [K, V][] | null): WeakMap; + readonly prototype: WeakMap; } declare var WeakMap: WeakMapConstructor; @@ -127,13 +127,7 @@ interface ReadonlySet { readonly size: number; } -type WeakKeyTypes = WeakKeyTypesStore[keyof WeakKeyTypesStore]; - -interface WeakKeyTypesStore { - object: object; -} - -interface WeakSet { +interface WeakSet { /** * Appends a new object to the end of the WeakSet. */ @@ -150,7 +144,7 @@ interface WeakSet { } interface WeakSetConstructor { - new (values?: readonly T[] | null): WeakSet; - readonly prototype: WeakSet; + new (values?: readonly T[] | null): WeakSet; + readonly prototype: WeakSet; } declare var WeakSet: WeakSetConstructor; diff --git a/lib/lib.es2015.iterable.d.ts b/lib/lib.es2015.iterable.d.ts index fecd3024f366c..8a7292383442d 100644 --- a/lib/lib.es2015.iterable.d.ts +++ b/lib/lib.es2015.iterable.d.ts @@ -161,10 +161,10 @@ interface MapConstructor { new (iterable?: Iterable | null): Map; } -interface WeakMap { } +interface WeakMap { } interface WeakMapConstructor { - new (iterable: Iterable): WeakMap; + new (iterable: Iterable): WeakMap; } interface Set { @@ -209,10 +209,10 @@ interface SetConstructor { new (iterable?: Iterable | null): Set; } -interface WeakSet { } +interface WeakSet { } interface WeakSetConstructor { - new (iterable: Iterable): WeakSet; + new (iterable: Iterable): WeakSet; } interface Promise { } diff --git a/lib/lib.es2015.symbol.wellknown.d.ts b/lib/lib.es2015.symbol.wellknown.d.ts index 13b265343321b..81e052bf26d27 100644 --- a/lib/lib.es2015.symbol.wellknown.d.ts +++ b/lib/lib.es2015.symbol.wellknown.d.ts @@ -135,7 +135,7 @@ interface Map { readonly [Symbol.toStringTag]: string; } -interface WeakMap { +interface WeakMap { readonly [Symbol.toStringTag]: string; } @@ -143,7 +143,7 @@ interface Set { readonly [Symbol.toStringTag]: string; } -interface WeakSet { +interface WeakSet { readonly [Symbol.toStringTag]: string; } diff --git a/lib/lib.es2021.weakref.d.ts b/lib/lib.es2021.weakref.d.ts index 6f67efd50315c..01ba9363c5480 100644 --- a/lib/lib.es2021.weakref.d.ts +++ b/lib/lib.es2021.weakref.d.ts @@ -17,7 +17,7 @@ and limitations under the License. /// -interface WeakRef { +interface WeakRef { readonly [Symbol.toStringTag]: "WeakRef"; /** @@ -34,7 +34,7 @@ interface WeakRefConstructor { * Creates a WeakRef instance for the given target object. * @param target The target object for the WeakRef instance. */ - new(target: T): WeakRef; + new(target: T): WeakRef; } declare var WeakRef: WeakRefConstructor; @@ -51,7 +51,7 @@ interface FinalizationRegistry { * object. If provided (and not undefined), this must be an object. If not provided, the target * cannot be unregistered. */ - register(target: symbol, heldValue: T, unregisterToken?: symbol): void; + register(target: object, heldValue: T, unregisterToken?: object): void; /** * Unregisters an object from the registry. From ff83b5c6bb2a67950f6cdaf9fb5618f92edb568e Mon Sep 17 00:00:00 2001 From: Leo Elmecker Date: Thu, 23 Mar 2023 00:19:37 +0000 Subject: [PATCH 19/24] Undo lib changes Signed-off-by: Leo Elmecker --- lib/lib.es2021.weakref.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/lib.es2021.weakref.d.ts b/lib/lib.es2021.weakref.d.ts index 01ba9363c5480..eb7764242d7b9 100644 --- a/lib/lib.es2021.weakref.d.ts +++ b/lib/lib.es2021.weakref.d.ts @@ -17,6 +17,7 @@ and limitations under the License. /// + interface WeakRef { readonly [Symbol.toStringTag]: "WeakRef"; From c3275ca0496b7752497aae9441858d65442c6e47 Mon Sep 17 00:00:00 2001 From: Leo Elmecker Date: Wed, 29 Mar 2023 23:25:29 +0100 Subject: [PATCH 20/24] Address PR comments Signed-off-by: Leo Elmecker --- src/compiler/commandLineParser.ts | 4 ++-- src/lib/es2015.collection.d.ts | 14 +++++++------- src/lib/es2015.iterable.d.ts | 8 ++++---- src/lib/es2015.symbol.wellknown.d.ts | 4 ++-- src/lib/es2021.weakref.d.ts | 4 ++-- src/lib/es2023.collection.d.ts | 12 ++++++------ src/lib/es2023.weakref.d.ts | 6 +++--- 7 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 1343e9d461b76..cf7383cbe2cc1 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -214,8 +214,8 @@ const libEntries: [string, string][] = [ ["es2023.collection", "lib.es2023.collection.d.ts"], ["es2023.weakref", "lib.es2023.weakref.d.ts"], ["esnext.array", "lib.es2023.array.d.ts"], - ["esnext.array", "lib.es2023.collection.d.ts"], - ["esnext.array", "lib.es2023.weakref.d.ts"], + ["esnext.collection", "lib.es2023.collection.d.ts"], + ["esnext.weakref", "lib.es2023.weakref.d.ts"], ["esnext.symbol", "lib.es2019.symbol.d.ts"], ["esnext.asynciterable", "lib.es2018.asynciterable.d.ts"], ["esnext.intl", "lib.esnext.intl.d.ts"], diff --git a/src/lib/es2015.collection.d.ts b/src/lib/es2015.collection.d.ts index 3ab7175543949..9a84882fbf89d 100644 --- a/src/lib/es2015.collection.d.ts +++ b/src/lib/es2015.collection.d.ts @@ -42,13 +42,13 @@ interface ReadonlyMap { readonly size: number; } -type WeakKeyTypes = WeakKeyTypesStore[keyof WeakKeyTypesStore]; - -interface WeakKeyTypesStore { +interface WeakKeyTypes { object: object; } -interface WeakMap { +type WeakKey = WeakKeyTypes[keyof WeakKeyTypes]; + +interface WeakMap { /** * Removes the specified element from the WeakMap. * @returns true if the element was successfully removed, or false if it was not present. @@ -113,7 +113,7 @@ interface ReadonlySet { readonly size: number; } -interface WeakSet { +interface WeakSet { /** * Appends a new object to the end of the WeakSet. */ @@ -130,7 +130,7 @@ interface WeakSet { } interface WeakSetConstructor { - new (values?: readonly T[] | null): WeakSet; - readonly prototype: WeakSet; + new (values?: readonly T[] | null): WeakSet; + readonly prototype: WeakSet; } declare var WeakSet: WeakSetConstructor; diff --git a/src/lib/es2015.iterable.d.ts b/src/lib/es2015.iterable.d.ts index ac5fe27670c78..c7b7afa72119d 100644 --- a/src/lib/es2015.iterable.d.ts +++ b/src/lib/es2015.iterable.d.ts @@ -141,10 +141,10 @@ interface MapConstructor { new (iterable?: Iterable | null): Map; } -interface WeakMap { } +interface WeakMap { } interface WeakMapConstructor { - new (iterable: Iterable): WeakMap; + new (iterable: Iterable): WeakMap; } interface Set { @@ -189,10 +189,10 @@ interface SetConstructor { new (iterable?: Iterable | null): Set; } -interface WeakSet { } +interface WeakSet { } interface WeakSetConstructor { - new (iterable: Iterable): WeakSet; + new (iterable: Iterable): WeakSet; } interface Promise { } diff --git a/src/lib/es2015.symbol.wellknown.d.ts b/src/lib/es2015.symbol.wellknown.d.ts index 643f402ea62b6..51134ff07dbfa 100644 --- a/src/lib/es2015.symbol.wellknown.d.ts +++ b/src/lib/es2015.symbol.wellknown.d.ts @@ -115,7 +115,7 @@ interface Map { readonly [Symbol.toStringTag]: string; } -interface WeakMap { +interface WeakMap { readonly [Symbol.toStringTag]: string; } @@ -123,7 +123,7 @@ interface Set { readonly [Symbol.toStringTag]: string; } -interface WeakSet { +interface WeakSet { readonly [Symbol.toStringTag]: string; } diff --git a/src/lib/es2021.weakref.d.ts b/src/lib/es2021.weakref.d.ts index aa8345e2d5886..4c55a26f99303 100644 --- a/src/lib/es2021.weakref.d.ts +++ b/src/lib/es2021.weakref.d.ts @@ -1,4 +1,4 @@ -interface WeakRef { +interface WeakRef { readonly [Symbol.toStringTag]: "WeakRef"; /** @@ -15,7 +15,7 @@ interface WeakRefConstructor { * Creates a WeakRef instance for the given target object. * @param target The target object for the WeakRef instance. */ - new(target: T): WeakRef; + new(target: T): WeakRef; } declare var WeakRef: WeakRefConstructor; diff --git a/src/lib/es2023.collection.d.ts b/src/lib/es2023.collection.d.ts index cfc69183956fe..ad3c66e6ca932 100644 --- a/src/lib/es2023.collection.d.ts +++ b/src/lib/es2023.collection.d.ts @@ -1,16 +1,16 @@ -interface WeakKeyTypesStore { +interface WeakKeyTypes { symbol: symbol; } -interface WeakSet {} +interface WeakSet {} interface WeakSetConstructor { - new (values?: readonly T[] | null): WeakSet; + new (values?: readonly T[] | null): WeakSet; } -interface WeakMap {} +interface WeakMap {} interface WeakMapConstructor { - new (entries?: readonly [K, V][] | null): WeakMap; - readonly prototype: WeakMap; + new (entries?: readonly [K, V][] | null): WeakMap; + readonly prototype: WeakMap; } \ No newline at end of file diff --git a/src/lib/es2023.weakref.d.ts b/src/lib/es2023.weakref.d.ts index 609dda30b3349..ce11d9b02157d 100644 --- a/src/lib/es2023.weakref.d.ts +++ b/src/lib/es2023.weakref.d.ts @@ -1,4 +1,4 @@ -interface WeakKeyTypesStore { +interface WeakKeyTypes { symbol: symbol; } @@ -36,7 +36,7 @@ interface FinalizationRegistryConstructor { declare var FinalizationRegistry: FinalizationRegistryConstructor; -interface WeakRef { +interface WeakRef { /** * Returns the WeakRef instance's target object, or undefined if the target object has been * reclaimed. @@ -45,5 +45,5 @@ interface WeakRef { } interface WeakRefConstructor { - new(target: T): WeakRef; + new(target: T): WeakRef; } \ No newline at end of file From 8c2fd5607fbf26fbf4fa0958ff9fe92b34859cca Mon Sep 17 00:00:00 2001 From: Leo Elmecker Date: Mon, 3 Apr 2023 13:34:54 +0100 Subject: [PATCH 21/24] Address PR comments Signed-off-by: Leo Elmecker --- src/compiler/commandLineParser.ts | 2 -- src/lib/es2015.collection.d.ts | 6 ---- src/lib/es2021.weakref.d.ts | 31 ++++++++++--------- src/lib/es2023.collection.d.ts | 13 -------- src/lib/es2023.d.ts | 1 - src/lib/es2023.weakref.d.ts | 49 ------------------------------- src/lib/es5.d.ts | 9 ++++++ src/lib/libs.json | 1 - 8 files changed, 26 insertions(+), 86 deletions(-) delete mode 100644 src/lib/es2023.weakref.d.ts diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index cf7383cbe2cc1..9fc8207629555 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -212,10 +212,8 @@ const libEntries: [string, string][] = [ ["es2022.regexp", "lib.es2022.regexp.d.ts"], ["es2023.array", "lib.es2023.array.d.ts"], ["es2023.collection", "lib.es2023.collection.d.ts"], - ["es2023.weakref", "lib.es2023.weakref.d.ts"], ["esnext.array", "lib.es2023.array.d.ts"], ["esnext.collection", "lib.es2023.collection.d.ts"], - ["esnext.weakref", "lib.es2023.weakref.d.ts"], ["esnext.symbol", "lib.es2019.symbol.d.ts"], ["esnext.asynciterable", "lib.es2018.asynciterable.d.ts"], ["esnext.intl", "lib.esnext.intl.d.ts"], diff --git a/src/lib/es2015.collection.d.ts b/src/lib/es2015.collection.d.ts index 9a84882fbf89d..8128fcccfd848 100644 --- a/src/lib/es2015.collection.d.ts +++ b/src/lib/es2015.collection.d.ts @@ -42,12 +42,6 @@ interface ReadonlyMap { readonly size: number; } -interface WeakKeyTypes { - object: object; -} - -type WeakKey = WeakKeyTypes[keyof WeakKeyTypes]; - interface WeakMap { /** * Removes the specified element from the WeakMap. diff --git a/src/lib/es2021.weakref.d.ts b/src/lib/es2021.weakref.d.ts index 4c55a26f99303..b8aac14ae51f9 100644 --- a/src/lib/es2021.weakref.d.ts +++ b/src/lib/es2021.weakref.d.ts @@ -2,8 +2,9 @@ interface WeakRef { readonly [Symbol.toStringTag]: "WeakRef"; /** - * Returns the WeakRef instance's target object, or undefined if the target object has been + * Returns the WeakRef instance's target value, or undefined if the target value has been * reclaimed. + * In es2023 the value can be either a symbol or an object, in previous versions only object is permissible. */ deref(): T | undefined; } @@ -12,8 +13,9 @@ interface WeakRefConstructor { readonly prototype: WeakRef; /** - * Creates a WeakRef instance for the given target object. - * @param target The target object for the WeakRef instance. + * Creates a WeakRef instance for the given target value. + * In es2023 the value can be either a symbol or an object, in previous versions only object is permissible. + * @param target The target value for the WeakRef instance. */ new(target: T): WeakRef; } @@ -24,22 +26,23 @@ interface FinalizationRegistry { readonly [Symbol.toStringTag]: "FinalizationRegistry"; /** - * Registers an object with the registry. - * @param target The target object to register. - * @param heldValue The value to pass to the finalizer for this object. This cannot be the - * target object. + * Registers a value with the registry. + * In es2023 the value can be either a symbol or an object, in previous versions only object is permissible. + * @param target The target value to register. + * @param heldValue The value to pass to the finalizer for this value. This cannot be the + * target value. * @param unregisterToken The token to pass to the unregister method to unregister the target - * object. If provided (and not undefined), this must be an object. If not provided, the target - * cannot be unregistered. + * value. If not provided, the target cannot be unregistered. */ - register(target: object, heldValue: T, unregisterToken?: object): void; + register(target: WeakKey, heldValue: T, unregisterToken?: WeakKey): void; /** - * Unregisters an object from the registry. + * Unregisters a value from the registry. + * In es2023 the value can be either a symbol or an object, in previous versions only object is permissible. * @param unregisterToken The token that was used as the unregisterToken argument when calling - * register to register the target object. + * register to register the target value. */ - unregister(unregisterToken: object): void; + unregister(unregisterToken: WeakKey): void; } interface FinalizationRegistryConstructor { @@ -47,7 +50,7 @@ interface FinalizationRegistryConstructor { /** * Creates a finalization registry with an associated cleanup callback - * @param cleanupCallback The callback to call after an object in the registry has been reclaimed. + * @param cleanupCallback The callback to call after a value in the registry has been reclaimed. */ new(cleanupCallback: (heldValue: T) => void): FinalizationRegistry; } diff --git a/src/lib/es2023.collection.d.ts b/src/lib/es2023.collection.d.ts index ad3c66e6ca932..77545a0a415c3 100644 --- a/src/lib/es2023.collection.d.ts +++ b/src/lib/es2023.collection.d.ts @@ -1,16 +1,3 @@ interface WeakKeyTypes { symbol: symbol; } - -interface WeakSet {} - -interface WeakSetConstructor { - new (values?: readonly T[] | null): WeakSet; -} - -interface WeakMap {} - -interface WeakMapConstructor { - new (entries?: readonly [K, V][] | null): WeakMap; - readonly prototype: WeakMap; -} \ No newline at end of file diff --git a/src/lib/es2023.d.ts b/src/lib/es2023.d.ts index 243142c103eda..5c45f807e08a8 100644 --- a/src/lib/es2023.d.ts +++ b/src/lib/es2023.d.ts @@ -1,4 +1,3 @@ /// /// /// -/// diff --git a/src/lib/es2023.weakref.d.ts b/src/lib/es2023.weakref.d.ts deleted file mode 100644 index ce11d9b02157d..0000000000000 --- a/src/lib/es2023.weakref.d.ts +++ /dev/null @@ -1,49 +0,0 @@ -interface WeakKeyTypes { - symbol: symbol; -} - -interface FinalizationRegistry { - readonly [Symbol.toStringTag]: "FinalizationRegistry"; - - /** - * Registers an object with the registry. - * @param target The target object to register. - * @param heldValue The value to pass to the finalizer for this object. This cannot be the - * target object. - * @param unregisterToken The token to pass to the unregister method to unregister the target - * object. If provided (and not undefined), this must be an object. If not provided, the target - * cannot be unregistered. - */ - registerSymbol(target: symbol, heldValue: T, unregisterToken?: symbol): void; - - /** - * Unregisters an object from the registry. - * @param unregisterToken The token that was used as the unregisterToken argument when calling - * register to register the target object. - */ - unregisterSymbol(unregisterToken: symbol): void; -} - -interface FinalizationRegistryConstructor { - readonly prototype: FinalizationRegistry; - - /** - * Creates a finalization registry with an associated cleanup callback - * @param cleanupCallback The callback to call after an object in the registry has been reclaimed. - */ - new(cleanupCallback: (heldValue: T) => void): FinalizationRegistry; -} - -declare var FinalizationRegistry: FinalizationRegistryConstructor; - -interface WeakRef { - /** - * Returns the WeakRef instance's target object, or undefined if the target object has been - * reclaimed. - */ - deref(): T | undefined; -} - -interface WeakRefConstructor { - new(target: T): WeakRef; -} \ No newline at end of file diff --git a/src/lib/es5.d.ts b/src/lib/es5.d.ts index a74b3cb4c2111..d562238bf3e83 100644 --- a/src/lib/es5.d.ts +++ b/src/lib/es5.d.ts @@ -1634,6 +1634,15 @@ type Uncapitalize = intrinsic; */ interface ThisType { } +/** + * Stores types to be used with WeakSet, WeakMap, WeakRef, and FinalizationRegistry + */ +interface WeakKeyTypes { + object: object; +} + +type WeakKey = WeakKeyTypes[keyof WeakKeyTypes]; + /** * Represents a raw buffer of binary data, which is used to store data for the * different typed arrays. ArrayBuffers cannot be read from or written to directly, diff --git a/src/lib/libs.json b/src/lib/libs.json index 27432a738d42b..5613674ef77d5 100644 --- a/src/lib/libs.json +++ b/src/lib/libs.json @@ -66,7 +66,6 @@ "es2022.regexp", "es2023.array", "es2023.collection", - "es2023.weakref", "esnext.intl", "decorators", "decorators.legacy", From 2eb035432c446de9ffee3f43db6da06907ce509b Mon Sep 17 00:00:00 2001 From: Leo Elmecker Date: Mon, 3 Apr 2023 13:35:23 +0100 Subject: [PATCH 22/24] Add baselines Signed-off-by: Leo Elmecker --- .../acceptSymbolAsWeakType.errors.txt | 28 +++++ .../reference/acceptSymbolAsWeakType.symbols | 79 +++++++++++++ .../reference/acceptSymbolAsWeakType.types | 106 ++++++++++++++++++ .../dissallowSymbolAsWeakType.symbols | 83 ++++++++++++++ .../reference/dissallowSymbolAsWeakType.types | 106 ++++++++++++++++++ 5 files changed, 402 insertions(+) create mode 100644 tests/baselines/reference/acceptSymbolAsWeakType.errors.txt create mode 100644 tests/baselines/reference/acceptSymbolAsWeakType.symbols create mode 100644 tests/baselines/reference/acceptSymbolAsWeakType.types create mode 100644 tests/baselines/reference/dissallowSymbolAsWeakType.symbols create mode 100644 tests/baselines/reference/dissallowSymbolAsWeakType.types diff --git a/tests/baselines/reference/acceptSymbolAsWeakType.errors.txt b/tests/baselines/reference/acceptSymbolAsWeakType.errors.txt new file mode 100644 index 0000000000000..c313082ab092e --- /dev/null +++ b/tests/baselines/reference/acceptSymbolAsWeakType.errors.txt @@ -0,0 +1,28 @@ +tests/cases/compiler/acceptSymbolAsWeakType.ts(18,3): error TS2339: Property 'registerSymbol' does not exist on type 'FinalizationRegistry'. +tests/cases/compiler/acceptSymbolAsWeakType.ts(19,3): error TS2339: Property 'unregisterSymbol' does not exist on type 'FinalizationRegistry'. + + +==== tests/cases/compiler/acceptSymbolAsWeakType.ts (2 errors) ==== + const s: symbol = Symbol('s'); + + const ws = new WeakSet([s]); + ws.add(s); + ws.has(s); + ws.delete(s); + + const wm = new WeakMap([[s, false]]); + wm.set(s, true); + wm.has(s); + wm.get(s); + wm.delete(s); + + const wr = new WeakRef(s); + wr.deref(); + + const f = new FinalizationRegistry(() => {}); + f.registerSymbol(s, null); + ~~~~~~~~~~~~~~ +!!! error TS2339: Property 'registerSymbol' does not exist on type 'FinalizationRegistry'. + f.unregisterSymbol(s); + ~~~~~~~~~~~~~~~~ +!!! error TS2339: Property 'unregisterSymbol' does not exist on type 'FinalizationRegistry'. \ No newline at end of file diff --git a/tests/baselines/reference/acceptSymbolAsWeakType.symbols b/tests/baselines/reference/acceptSymbolAsWeakType.symbols new file mode 100644 index 0000000000000..801006ef5763a --- /dev/null +++ b/tests/baselines/reference/acceptSymbolAsWeakType.symbols @@ -0,0 +1,79 @@ +=== tests/cases/compiler/acceptSymbolAsWeakType.ts === +const s: symbol = Symbol('s'); +>s : Symbol(s, Decl(acceptSymbolAsWeakType.ts, 0, 5)) +>Symbol : Symbol(Symbol, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2019.symbol.d.ts, --, --)) + +const ws = new WeakSet([s]); +>ws : Symbol(ws, Decl(acceptSymbolAsWeakType.ts, 2, 5)) +>WeakSet : Symbol(WeakSet, Decl(lib.es2015.collection.d.ts, --, --), Decl(lib.es2015.collection.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) +>s : Symbol(s, Decl(acceptSymbolAsWeakType.ts, 0, 5)) + +ws.add(s); +>ws.add : Symbol(WeakSet.add, Decl(lib.es2015.collection.d.ts, --, --)) +>ws : Symbol(ws, Decl(acceptSymbolAsWeakType.ts, 2, 5)) +>add : Symbol(WeakSet.add, Decl(lib.es2015.collection.d.ts, --, --)) +>s : Symbol(s, Decl(acceptSymbolAsWeakType.ts, 0, 5)) + +ws.has(s); +>ws.has : Symbol(WeakSet.has, Decl(lib.es2015.collection.d.ts, --, --)) +>ws : Symbol(ws, Decl(acceptSymbolAsWeakType.ts, 2, 5)) +>has : Symbol(WeakSet.has, Decl(lib.es2015.collection.d.ts, --, --)) +>s : Symbol(s, Decl(acceptSymbolAsWeakType.ts, 0, 5)) + +ws.delete(s); +>ws.delete : Symbol(WeakSet.delete, Decl(lib.es2015.collection.d.ts, --, --)) +>ws : Symbol(ws, Decl(acceptSymbolAsWeakType.ts, 2, 5)) +>delete : Symbol(WeakSet.delete, Decl(lib.es2015.collection.d.ts, --, --)) +>s : Symbol(s, Decl(acceptSymbolAsWeakType.ts, 0, 5)) + +const wm = new WeakMap([[s, false]]); +>wm : Symbol(wm, Decl(acceptSymbolAsWeakType.ts, 7, 5)) +>WeakMap : Symbol(WeakMap, Decl(lib.es2015.collection.d.ts, --, --), Decl(lib.es2015.collection.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) +>s : Symbol(s, Decl(acceptSymbolAsWeakType.ts, 0, 5)) + +wm.set(s, true); +>wm.set : Symbol(WeakMap.set, Decl(lib.es2015.collection.d.ts, --, --)) +>wm : Symbol(wm, Decl(acceptSymbolAsWeakType.ts, 7, 5)) +>set : Symbol(WeakMap.set, Decl(lib.es2015.collection.d.ts, --, --)) +>s : Symbol(s, Decl(acceptSymbolAsWeakType.ts, 0, 5)) + +wm.has(s); +>wm.has : Symbol(WeakMap.has, Decl(lib.es2015.collection.d.ts, --, --)) +>wm : Symbol(wm, Decl(acceptSymbolAsWeakType.ts, 7, 5)) +>has : Symbol(WeakMap.has, Decl(lib.es2015.collection.d.ts, --, --)) +>s : Symbol(s, Decl(acceptSymbolAsWeakType.ts, 0, 5)) + +wm.get(s); +>wm.get : Symbol(WeakMap.get, Decl(lib.es2015.collection.d.ts, --, --)) +>wm : Symbol(wm, Decl(acceptSymbolAsWeakType.ts, 7, 5)) +>get : Symbol(WeakMap.get, Decl(lib.es2015.collection.d.ts, --, --)) +>s : Symbol(s, Decl(acceptSymbolAsWeakType.ts, 0, 5)) + +wm.delete(s); +>wm.delete : Symbol(WeakMap.delete, Decl(lib.es2015.collection.d.ts, --, --)) +>wm : Symbol(wm, Decl(acceptSymbolAsWeakType.ts, 7, 5)) +>delete : Symbol(WeakMap.delete, Decl(lib.es2015.collection.d.ts, --, --)) +>s : Symbol(s, Decl(acceptSymbolAsWeakType.ts, 0, 5)) + +const wr = new WeakRef(s); +>wr : Symbol(wr, Decl(acceptSymbolAsWeakType.ts, 13, 5)) +>WeakRef : Symbol(WeakRef, Decl(lib.es2021.weakref.d.ts, --, --), Decl(lib.es2021.weakref.d.ts, --, --)) +>s : Symbol(s, Decl(acceptSymbolAsWeakType.ts, 0, 5)) + +wr.deref(); +>wr.deref : Symbol(WeakRef.deref, Decl(lib.es2021.weakref.d.ts, --, --)) +>wr : Symbol(wr, Decl(acceptSymbolAsWeakType.ts, 13, 5)) +>deref : Symbol(WeakRef.deref, Decl(lib.es2021.weakref.d.ts, --, --)) + +const f = new FinalizationRegistry(() => {}); +>f : Symbol(f, Decl(acceptSymbolAsWeakType.ts, 16, 5)) +>FinalizationRegistry : Symbol(FinalizationRegistry, Decl(lib.es2021.weakref.d.ts, --, --), Decl(lib.es2021.weakref.d.ts, --, --)) + +f.registerSymbol(s, null); +>f : Symbol(f, Decl(acceptSymbolAsWeakType.ts, 16, 5)) +>s : Symbol(s, Decl(acceptSymbolAsWeakType.ts, 0, 5)) + +f.unregisterSymbol(s); +>f : Symbol(f, Decl(acceptSymbolAsWeakType.ts, 16, 5)) +>s : Symbol(s, Decl(acceptSymbolAsWeakType.ts, 0, 5)) + diff --git a/tests/baselines/reference/acceptSymbolAsWeakType.types b/tests/baselines/reference/acceptSymbolAsWeakType.types new file mode 100644 index 0000000000000..6fa86903f2475 --- /dev/null +++ b/tests/baselines/reference/acceptSymbolAsWeakType.types @@ -0,0 +1,106 @@ +=== tests/cases/compiler/acceptSymbolAsWeakType.ts === +const s: symbol = Symbol('s'); +>s : symbol +>Symbol('s') : unique symbol +>Symbol : SymbolConstructor +>'s' : "s" + +const ws = new WeakSet([s]); +>ws : WeakSet +>new WeakSet([s]) : WeakSet +>WeakSet : WeakSetConstructor +>[s] : symbol[] +>s : symbol + +ws.add(s); +>ws.add(s) : WeakSet +>ws.add : (value: symbol) => WeakSet +>ws : WeakSet +>add : (value: symbol) => WeakSet +>s : symbol + +ws.has(s); +>ws.has(s) : boolean +>ws.has : (value: symbol) => boolean +>ws : WeakSet +>has : (value: symbol) => boolean +>s : symbol + +ws.delete(s); +>ws.delete(s) : boolean +>ws.delete : (value: symbol) => boolean +>ws : WeakSet +>delete : (value: symbol) => boolean +>s : symbol + +const wm = new WeakMap([[s, false]]); +>wm : WeakMap +>new WeakMap([[s, false]]) : WeakMap +>WeakMap : WeakMapConstructor +>[[s, false]] : [symbol, false][] +>[s, false] : [symbol, false] +>s : symbol +>false : false + +wm.set(s, true); +>wm.set(s, true) : WeakMap +>wm.set : (key: symbol, value: boolean) => WeakMap +>wm : WeakMap +>set : (key: symbol, value: boolean) => WeakMap +>s : symbol +>true : true + +wm.has(s); +>wm.has(s) : boolean +>wm.has : (key: symbol) => boolean +>wm : WeakMap +>has : (key: symbol) => boolean +>s : symbol + +wm.get(s); +>wm.get(s) : boolean +>wm.get : (key: symbol) => boolean +>wm : WeakMap +>get : (key: symbol) => boolean +>s : symbol + +wm.delete(s); +>wm.delete(s) : boolean +>wm.delete : (key: symbol) => boolean +>wm : WeakMap +>delete : (key: symbol) => boolean +>s : symbol + +const wr = new WeakRef(s); +>wr : WeakRef +>new WeakRef(s) : WeakRef +>WeakRef : WeakRefConstructor +>s : symbol + +wr.deref(); +>wr.deref() : symbol +>wr.deref : () => symbol +>wr : WeakRef +>deref : () => symbol + +const f = new FinalizationRegistry(() => {}); +>f : FinalizationRegistry +>new FinalizationRegistry(() => {}) : FinalizationRegistry +>FinalizationRegistry : FinalizationRegistryConstructor +>() => {} : () => void + +f.registerSymbol(s, null); +>f.registerSymbol(s, null) : any +>f.registerSymbol : any +>f : FinalizationRegistry +>registerSymbol : any +>s : symbol +>null : null + +f.unregisterSymbol(s); +>f.unregisterSymbol(s) : any +>f.unregisterSymbol : any +>f : FinalizationRegistry +>unregisterSymbol : any +>s : symbol + diff --git a/tests/baselines/reference/dissallowSymbolAsWeakType.symbols b/tests/baselines/reference/dissallowSymbolAsWeakType.symbols new file mode 100644 index 0000000000000..8eae3976daa47 --- /dev/null +++ b/tests/baselines/reference/dissallowSymbolAsWeakType.symbols @@ -0,0 +1,83 @@ +=== tests/cases/compiler/dissallowSymbolAsWeakType.ts === +const s: symbol = Symbol('s'); +>s : Symbol(s, Decl(dissallowSymbolAsWeakType.ts, 0, 5)) +>Symbol : Symbol(Symbol, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2019.symbol.d.ts, --, --)) + +const ws = new WeakSet([s]); +>ws : Symbol(ws, Decl(dissallowSymbolAsWeakType.ts, 2, 5)) +>WeakSet : Symbol(WeakSet, Decl(lib.es2015.collection.d.ts, --, --), Decl(lib.es2015.collection.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) +>s : Symbol(s, Decl(dissallowSymbolAsWeakType.ts, 0, 5)) + +ws.add(s); +>ws.add : Symbol(WeakSet.add, Decl(lib.es2015.collection.d.ts, --, --)) +>ws : Symbol(ws, Decl(dissallowSymbolAsWeakType.ts, 2, 5)) +>add : Symbol(WeakSet.add, Decl(lib.es2015.collection.d.ts, --, --)) +>s : Symbol(s, Decl(dissallowSymbolAsWeakType.ts, 0, 5)) + +ws.has(s); +>ws.has : Symbol(WeakSet.has, Decl(lib.es2015.collection.d.ts, --, --)) +>ws : Symbol(ws, Decl(dissallowSymbolAsWeakType.ts, 2, 5)) +>has : Symbol(WeakSet.has, Decl(lib.es2015.collection.d.ts, --, --)) +>s : Symbol(s, Decl(dissallowSymbolAsWeakType.ts, 0, 5)) + +ws.delete(s); +>ws.delete : Symbol(WeakSet.delete, Decl(lib.es2015.collection.d.ts, --, --)) +>ws : Symbol(ws, Decl(dissallowSymbolAsWeakType.ts, 2, 5)) +>delete : Symbol(WeakSet.delete, Decl(lib.es2015.collection.d.ts, --, --)) +>s : Symbol(s, Decl(dissallowSymbolAsWeakType.ts, 0, 5)) + +const wm = new WeakMap([[s, false]]); +>wm : Symbol(wm, Decl(dissallowSymbolAsWeakType.ts, 7, 5)) +>WeakMap : Symbol(WeakMap, Decl(lib.es2015.collection.d.ts, --, --), Decl(lib.es2015.collection.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) +>s : Symbol(s, Decl(dissallowSymbolAsWeakType.ts, 0, 5)) + +wm.set(s, true); +>wm.set : Symbol(WeakMap.set, Decl(lib.es2015.collection.d.ts, --, --)) +>wm : Symbol(wm, Decl(dissallowSymbolAsWeakType.ts, 7, 5)) +>set : Symbol(WeakMap.set, Decl(lib.es2015.collection.d.ts, --, --)) +>s : Symbol(s, Decl(dissallowSymbolAsWeakType.ts, 0, 5)) + +wm.has(s); +>wm.has : Symbol(WeakMap.has, Decl(lib.es2015.collection.d.ts, --, --)) +>wm : Symbol(wm, Decl(dissallowSymbolAsWeakType.ts, 7, 5)) +>has : Symbol(WeakMap.has, Decl(lib.es2015.collection.d.ts, --, --)) +>s : Symbol(s, Decl(dissallowSymbolAsWeakType.ts, 0, 5)) + +wm.get(s); +>wm.get : Symbol(WeakMap.get, Decl(lib.es2015.collection.d.ts, --, --)) +>wm : Symbol(wm, Decl(dissallowSymbolAsWeakType.ts, 7, 5)) +>get : Symbol(WeakMap.get, Decl(lib.es2015.collection.d.ts, --, --)) +>s : Symbol(s, Decl(dissallowSymbolAsWeakType.ts, 0, 5)) + +wm.delete(s); +>wm.delete : Symbol(WeakMap.delete, Decl(lib.es2015.collection.d.ts, --, --)) +>wm : Symbol(wm, Decl(dissallowSymbolAsWeakType.ts, 7, 5)) +>delete : Symbol(WeakMap.delete, Decl(lib.es2015.collection.d.ts, --, --)) +>s : Symbol(s, Decl(dissallowSymbolAsWeakType.ts, 0, 5)) + +const wr = new WeakRef(s); +>wr : Symbol(wr, Decl(dissallowSymbolAsWeakType.ts, 13, 5)) +>WeakRef : Symbol(WeakRef, Decl(lib.es2021.weakref.d.ts, --, --), Decl(lib.es2021.weakref.d.ts, --, --)) +>s : Symbol(s, Decl(dissallowSymbolAsWeakType.ts, 0, 5)) + +wr.deref(); +>wr.deref : Symbol(WeakRef.deref, Decl(lib.es2021.weakref.d.ts, --, --)) +>wr : Symbol(wr, Decl(dissallowSymbolAsWeakType.ts, 13, 5)) +>deref : Symbol(WeakRef.deref, Decl(lib.es2021.weakref.d.ts, --, --)) + +const f = new FinalizationRegistry(() => {}); +>f : Symbol(f, Decl(dissallowSymbolAsWeakType.ts, 16, 5)) +>FinalizationRegistry : Symbol(FinalizationRegistry, Decl(lib.es2021.weakref.d.ts, --, --), Decl(lib.es2021.weakref.d.ts, --, --)) + +f.register(s, null); +>f.register : Symbol(FinalizationRegistry.register, Decl(lib.es2021.weakref.d.ts, --, --)) +>f : Symbol(f, Decl(dissallowSymbolAsWeakType.ts, 16, 5)) +>register : Symbol(FinalizationRegistry.register, Decl(lib.es2021.weakref.d.ts, --, --)) +>s : Symbol(s, Decl(dissallowSymbolAsWeakType.ts, 0, 5)) + +f.unregister(s); +>f.unregister : Symbol(FinalizationRegistry.unregister, Decl(lib.es2021.weakref.d.ts, --, --)) +>f : Symbol(f, Decl(dissallowSymbolAsWeakType.ts, 16, 5)) +>unregister : Symbol(FinalizationRegistry.unregister, Decl(lib.es2021.weakref.d.ts, --, --)) +>s : Symbol(s, Decl(dissallowSymbolAsWeakType.ts, 0, 5)) + diff --git a/tests/baselines/reference/dissallowSymbolAsWeakType.types b/tests/baselines/reference/dissallowSymbolAsWeakType.types new file mode 100644 index 0000000000000..937b5994399db --- /dev/null +++ b/tests/baselines/reference/dissallowSymbolAsWeakType.types @@ -0,0 +1,106 @@ +=== tests/cases/compiler/dissallowSymbolAsWeakType.ts === +const s: symbol = Symbol('s'); +>s : symbol +>Symbol('s') : unique symbol +>Symbol : SymbolConstructor +>'s' : "s" + +const ws = new WeakSet([s]); +>ws : WeakSet +>new WeakSet([s]) : WeakSet +>WeakSet : WeakSetConstructor +>[s] : symbol[] +>s : symbol + +ws.add(s); +>ws.add(s) : WeakSet +>ws.add : (value: object) => WeakSet +>ws : WeakSet +>add : (value: object) => WeakSet +>s : symbol + +ws.has(s); +>ws.has(s) : boolean +>ws.has : (value: object) => boolean +>ws : WeakSet +>has : (value: object) => boolean +>s : symbol + +ws.delete(s); +>ws.delete(s) : boolean +>ws.delete : (value: object) => boolean +>ws : WeakSet +>delete : (value: object) => boolean +>s : symbol + +const wm = new WeakMap([[s, false]]); +>wm : WeakMap +>new WeakMap([[s, false]]) : WeakMap +>WeakMap : WeakMapConstructor +>[[s, false]] : [symbol, false][] +>[s, false] : [symbol, false] +>s : symbol +>false : false + +wm.set(s, true); +>wm.set(s, true) : WeakMap +>wm.set : (key: object, value: boolean) => WeakMap +>wm : WeakMap +>set : (key: object, value: boolean) => WeakMap +>s : symbol +>true : true + +wm.has(s); +>wm.has(s) : boolean +>wm.has : (key: object) => boolean +>wm : WeakMap +>has : (key: object) => boolean +>s : symbol + +wm.get(s); +>wm.get(s) : boolean +>wm.get : (key: object) => boolean +>wm : WeakMap +>get : (key: object) => boolean +>s : symbol + +wm.delete(s); +>wm.delete(s) : boolean +>wm.delete : (key: object) => boolean +>wm : WeakMap +>delete : (key: object) => boolean +>s : symbol + +const wr = new WeakRef(s); +>wr : WeakRef +>new WeakRef(s) : WeakRef +>WeakRef : WeakRefConstructor +>s : symbol + +wr.deref(); +>wr.deref() : object +>wr.deref : () => object +>wr : WeakRef +>deref : () => object + +const f = new FinalizationRegistry(() => {}); +>f : FinalizationRegistry +>new FinalizationRegistry(() => {}) : FinalizationRegistry +>FinalizationRegistry : FinalizationRegistryConstructor +>() => {} : () => void + +f.register(s, null); +>f.register(s, null) : void +>f.register : (target: object, heldValue: unknown, unregisterToken?: object) => void +>f : FinalizationRegistry +>register : (target: object, heldValue: unknown, unregisterToken?: object) => void +>s : symbol +>null : null + +f.unregister(s); +>f.unregister(s) : void +>f.unregister : (unregisterToken: object) => void +>f : FinalizationRegistry +>unregister : (unregisterToken: object) => void +>s : symbol + From 7563f5e7670289844fc880bbc84fe38102cd14de Mon Sep 17 00:00:00 2001 From: Leo Elmecker Date: Wed, 5 Apr 2023 22:18:06 +0100 Subject: [PATCH 23/24] Address PR comments --- src/lib/es2015.collection.d.ts | 10 +++---- .../acceptSymbolAsWeakType.errors.txt | 15 ++++------ .../reference/acceptSymbolAsWeakType.js | 9 +++--- .../reference/acceptSymbolAsWeakType.symbols | 8 ++++-- .../reference/acceptSymbolAsWeakType.types | 28 +++++++++---------- .../cases/compiler/acceptSymbolAsWeakType.ts | 5 ++-- 6 files changed, 39 insertions(+), 36 deletions(-) diff --git a/src/lib/es2015.collection.d.ts b/src/lib/es2015.collection.d.ts index 8128fcccfd848..752d0500b0933 100644 --- a/src/lib/es2015.collection.d.ts +++ b/src/lib/es2015.collection.d.ts @@ -58,14 +58,14 @@ interface WeakMap { has(key: K): boolean; /** * Adds a new element with a specified key and value. - * @param key Must be an object. + * @param key Must be an object or symbol. */ set(key: K, value: V): this; } interface WeakMapConstructor { - new (entries?: readonly [K, V][] | null): WeakMap; - readonly prototype: WeakMap; + new (entries?: readonly [K, V][] | null): WeakMap; + readonly prototype: WeakMap; } declare var WeakMap: WeakMapConstructor; @@ -109,7 +109,7 @@ interface ReadonlySet { interface WeakSet { /** - * Appends a new object to the end of the WeakSet. + * Appends a new value to the end of the WeakSet. */ add(value: T): this; /** @@ -118,7 +118,7 @@ interface WeakSet { */ delete(value: T): boolean; /** - * @returns a boolean indicating whether an object exists in the WeakSet or not. + * @returns a boolean indicating whether a value exists in the WeakSet or not. */ has(value: T): boolean; } diff --git a/tests/baselines/reference/acceptSymbolAsWeakType.errors.txt b/tests/baselines/reference/acceptSymbolAsWeakType.errors.txt index c313082ab092e..90ef0daae3cac 100644 --- a/tests/baselines/reference/acceptSymbolAsWeakType.errors.txt +++ b/tests/baselines/reference/acceptSymbolAsWeakType.errors.txt @@ -1,8 +1,7 @@ -tests/cases/compiler/acceptSymbolAsWeakType.ts(18,3): error TS2339: Property 'registerSymbol' does not exist on type 'FinalizationRegistry'. -tests/cases/compiler/acceptSymbolAsWeakType.ts(19,3): error TS2339: Property 'unregisterSymbol' does not exist on type 'FinalizationRegistry'. +tests/cases/compiler/acceptSymbolAsWeakType.ts(18,15): error TS2345: Argument of type 'null' is not assignable to parameter of type 'symbol'. -==== tests/cases/compiler/acceptSymbolAsWeakType.ts (2 errors) ==== +==== tests/cases/compiler/acceptSymbolAsWeakType.ts (1 errors) ==== const s: symbol = Symbol('s'); const ws = new WeakSet([s]); @@ -20,9 +19,7 @@ tests/cases/compiler/acceptSymbolAsWeakType.ts(19,3): error TS2339: Property 'un wr.deref(); const f = new FinalizationRegistry(() => {}); - f.registerSymbol(s, null); - ~~~~~~~~~~~~~~ -!!! error TS2339: Property 'registerSymbol' does not exist on type 'FinalizationRegistry'. - f.unregisterSymbol(s); - ~~~~~~~~~~~~~~~~ -!!! error TS2339: Property 'unregisterSymbol' does not exist on type 'FinalizationRegistry'. \ No newline at end of file + f.register(s, null); + ~~~~ +!!! error TS2345: Argument of type 'null' is not assignable to parameter of type 'symbol'. + f.unregister(s); \ No newline at end of file diff --git a/tests/baselines/reference/acceptSymbolAsWeakType.js b/tests/baselines/reference/acceptSymbolAsWeakType.js index d562d9cce9157..f418dab832678 100644 --- a/tests/baselines/reference/acceptSymbolAsWeakType.js +++ b/tests/baselines/reference/acceptSymbolAsWeakType.js @@ -16,10 +16,11 @@ const wr = new WeakRef(s); wr.deref(); const f = new FinalizationRegistry(() => {}); -f.registerSymbol(s, null); -f.unregisterSymbol(s); +f.register(s, null); +f.unregister(s); //// [acceptSymbolAsWeakType.js] +"use strict"; const s = Symbol('s'); const ws = new WeakSet([s]); ws.add(s); @@ -33,5 +34,5 @@ wm.delete(s); const wr = new WeakRef(s); wr.deref(); const f = new FinalizationRegistry(() => { }); -f.registerSymbol(s, null); -f.unregisterSymbol(s); +f.register(s, null); +f.unregister(s); diff --git a/tests/baselines/reference/acceptSymbolAsWeakType.symbols b/tests/baselines/reference/acceptSymbolAsWeakType.symbols index 801006ef5763a..f3aa557743123 100644 --- a/tests/baselines/reference/acceptSymbolAsWeakType.symbols +++ b/tests/baselines/reference/acceptSymbolAsWeakType.symbols @@ -69,11 +69,15 @@ const f = new FinalizationRegistry(() => {}); >f : Symbol(f, Decl(acceptSymbolAsWeakType.ts, 16, 5)) >FinalizationRegistry : Symbol(FinalizationRegistry, Decl(lib.es2021.weakref.d.ts, --, --), Decl(lib.es2021.weakref.d.ts, --, --)) -f.registerSymbol(s, null); +f.register(s, null); +>f.register : Symbol(FinalizationRegistry.register, Decl(lib.es2021.weakref.d.ts, --, --)) >f : Symbol(f, Decl(acceptSymbolAsWeakType.ts, 16, 5)) +>register : Symbol(FinalizationRegistry.register, Decl(lib.es2021.weakref.d.ts, --, --)) >s : Symbol(s, Decl(acceptSymbolAsWeakType.ts, 0, 5)) -f.unregisterSymbol(s); +f.unregister(s); +>f.unregister : Symbol(FinalizationRegistry.unregister, Decl(lib.es2021.weakref.d.ts, --, --)) >f : Symbol(f, Decl(acceptSymbolAsWeakType.ts, 16, 5)) +>unregister : Symbol(FinalizationRegistry.unregister, Decl(lib.es2021.weakref.d.ts, --, --)) >s : Symbol(s, Decl(acceptSymbolAsWeakType.ts, 0, 5)) diff --git a/tests/baselines/reference/acceptSymbolAsWeakType.types b/tests/baselines/reference/acceptSymbolAsWeakType.types index 6fa86903f2475..aeed840af7617 100644 --- a/tests/baselines/reference/acceptSymbolAsWeakType.types +++ b/tests/baselines/reference/acceptSymbolAsWeakType.types @@ -58,10 +58,10 @@ wm.has(s); >s : symbol wm.get(s); ->wm.get(s) : boolean ->wm.get : (key: symbol) => boolean +>wm.get(s) : boolean | undefined +>wm.get : (key: symbol) => boolean | undefined >wm : WeakMap ->get : (key: symbol) => boolean +>get : (key: symbol) => boolean | undefined >s : symbol wm.delete(s); @@ -78,10 +78,10 @@ const wr = new WeakRef(s); >s : symbol wr.deref(); ->wr.deref() : symbol ->wr.deref : () => symbol +>wr.deref() : symbol | undefined +>wr.deref : () => symbol | undefined >wr : WeakRef ->deref : () => symbol +>deref : () => symbol | undefined const f = new FinalizationRegistry(() => {}); >f : FinalizationRegistry @@ -89,18 +89,18 @@ const f = new FinalizationRegistry(() => {}); >FinalizationRegistry : FinalizationRegistryConstructor >() => {} : () => void -f.registerSymbol(s, null); ->f.registerSymbol(s, null) : any ->f.registerSymbol : any +f.register(s, null); +>f.register(s, null) : void +>f.register : (target: WeakKey, heldValue: symbol, unregisterToken?: WeakKey | undefined) => void >f : FinalizationRegistry ->registerSymbol : any +>register : (target: WeakKey, heldValue: symbol, unregisterToken?: WeakKey | undefined) => void >s : symbol >null : null -f.unregisterSymbol(s); ->f.unregisterSymbol(s) : any ->f.unregisterSymbol : any +f.unregister(s); +>f.unregister(s) : void +>f.unregister : (unregisterToken: WeakKey) => void >f : FinalizationRegistry ->unregisterSymbol : any +>unregister : (unregisterToken: WeakKey) => void >s : symbol diff --git a/tests/cases/compiler/acceptSymbolAsWeakType.ts b/tests/cases/compiler/acceptSymbolAsWeakType.ts index 35dc147ac953a..53f8ea5ff0ead 100644 --- a/tests/cases/compiler/acceptSymbolAsWeakType.ts +++ b/tests/cases/compiler/acceptSymbolAsWeakType.ts @@ -1,3 +1,4 @@ +// @strict: true // @lib: esnext // @target: esnext @@ -18,5 +19,5 @@ const wr = new WeakRef(s); wr.deref(); const f = new FinalizationRegistry(() => {}); -f.registerSymbol(s, null); -f.unregisterSymbol(s); \ No newline at end of file +f.register(s, null); +f.unregister(s); \ No newline at end of file From 71b47cbbf45b34e9f992c685e92b81fba95544ce Mon Sep 17 00:00:00 2001 From: Leo Elmecker Date: Thu, 6 Apr 2023 16:22:50 +0100 Subject: [PATCH 24/24] Address PR comments --- .../acceptSymbolAsWeakType.errors.txt | 25 ------------------- .../reference/acceptSymbolAsWeakType.js | 2 +- .../reference/acceptSymbolAsWeakType.symbols | 2 +- .../reference/acceptSymbolAsWeakType.types | 14 +++++------ .../Parse --lib option with extra comma.js | 2 +- ... --lib option with trailing white-space.js | 2 +- .../Parse invalid option of library flags.js | 2 +- .../esNextWeakRefs_IterableWeakMap.types | 8 +++--- ...does-not-add-color-when-NO_COLOR-is-set.js | 2 +- ...-when-host-can't-provide-terminal-width.js | 2 +- ...tatus.DiagnosticsPresent_OutputsSkipped.js | 2 +- .../cases/compiler/acceptSymbolAsWeakType.ts | 2 +- 12 files changed, 20 insertions(+), 45 deletions(-) delete mode 100644 tests/baselines/reference/acceptSymbolAsWeakType.errors.txt diff --git a/tests/baselines/reference/acceptSymbolAsWeakType.errors.txt b/tests/baselines/reference/acceptSymbolAsWeakType.errors.txt deleted file mode 100644 index 90ef0daae3cac..0000000000000 --- a/tests/baselines/reference/acceptSymbolAsWeakType.errors.txt +++ /dev/null @@ -1,25 +0,0 @@ -tests/cases/compiler/acceptSymbolAsWeakType.ts(18,15): error TS2345: Argument of type 'null' is not assignable to parameter of type 'symbol'. - - -==== tests/cases/compiler/acceptSymbolAsWeakType.ts (1 errors) ==== - const s: symbol = Symbol('s'); - - const ws = new WeakSet([s]); - ws.add(s); - ws.has(s); - ws.delete(s); - - const wm = new WeakMap([[s, false]]); - wm.set(s, true); - wm.has(s); - wm.get(s); - wm.delete(s); - - const wr = new WeakRef(s); - wr.deref(); - - const f = new FinalizationRegistry(() => {}); - f.register(s, null); - ~~~~ -!!! error TS2345: Argument of type 'null' is not assignable to parameter of type 'symbol'. - f.unregister(s); \ No newline at end of file diff --git a/tests/baselines/reference/acceptSymbolAsWeakType.js b/tests/baselines/reference/acceptSymbolAsWeakType.js index f418dab832678..d0a55671178c3 100644 --- a/tests/baselines/reference/acceptSymbolAsWeakType.js +++ b/tests/baselines/reference/acceptSymbolAsWeakType.js @@ -15,7 +15,7 @@ wm.delete(s); const wr = new WeakRef(s); wr.deref(); -const f = new FinalizationRegistry(() => {}); +const f = new FinalizationRegistry(() => {}); f.register(s, null); f.unregister(s); diff --git a/tests/baselines/reference/acceptSymbolAsWeakType.symbols b/tests/baselines/reference/acceptSymbolAsWeakType.symbols index f3aa557743123..42e494fdb6e25 100644 --- a/tests/baselines/reference/acceptSymbolAsWeakType.symbols +++ b/tests/baselines/reference/acceptSymbolAsWeakType.symbols @@ -65,7 +65,7 @@ wr.deref(); >wr : Symbol(wr, Decl(acceptSymbolAsWeakType.ts, 13, 5)) >deref : Symbol(WeakRef.deref, Decl(lib.es2021.weakref.d.ts, --, --)) -const f = new FinalizationRegistry(() => {}); +const f = new FinalizationRegistry(() => {}); >f : Symbol(f, Decl(acceptSymbolAsWeakType.ts, 16, 5)) >FinalizationRegistry : Symbol(FinalizationRegistry, Decl(lib.es2021.weakref.d.ts, --, --), Decl(lib.es2021.weakref.d.ts, --, --)) diff --git a/tests/baselines/reference/acceptSymbolAsWeakType.types b/tests/baselines/reference/acceptSymbolAsWeakType.types index aeed840af7617..6277be0935b03 100644 --- a/tests/baselines/reference/acceptSymbolAsWeakType.types +++ b/tests/baselines/reference/acceptSymbolAsWeakType.types @@ -83,24 +83,24 @@ wr.deref(); >wr : WeakRef >deref : () => symbol | undefined -const f = new FinalizationRegistry(() => {}); ->f : FinalizationRegistry ->new FinalizationRegistry(() => {}) : FinalizationRegistry +const f = new FinalizationRegistry(() => {}); +>f : FinalizationRegistry +>new FinalizationRegistry(() => {}) : FinalizationRegistry >FinalizationRegistry : FinalizationRegistryConstructor >() => {} : () => void f.register(s, null); >f.register(s, null) : void ->f.register : (target: WeakKey, heldValue: symbol, unregisterToken?: WeakKey | undefined) => void ->f : FinalizationRegistry ->register : (target: WeakKey, heldValue: symbol, unregisterToken?: WeakKey | undefined) => void +>f.register : (target: WeakKey, heldValue: unknown, unregisterToken?: WeakKey | undefined) => void +>f : FinalizationRegistry +>register : (target: WeakKey, heldValue: unknown, unregisterToken?: WeakKey | undefined) => void >s : symbol >null : null f.unregister(s); >f.unregister(s) : void >f.unregister : (unregisterToken: WeakKey) => void ->f : FinalizationRegistry +>f : FinalizationRegistry >unregister : (unregisterToken: WeakKey) => void >s : symbol diff --git a/tests/baselines/reference/config/commandLineParsing/parseCommandLine/Parse --lib option with extra comma.js b/tests/baselines/reference/config/commandLineParsing/parseCommandLine/Parse --lib option with extra comma.js index 1ceb78426146d..4232c899d877e 100644 --- a/tests/baselines/reference/config/commandLineParsing/parseCommandLine/Parse --lib option with extra comma.js +++ b/tests/baselines/reference/config/commandLineParsing/parseCommandLine/Parse --lib option with extra comma.js @@ -10,4 +10,4 @@ WatchOptions:: FileNames:: es7,0.ts Errors:: -error TS6046: Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'es2018', 'es2019', 'es2020', 'es2021', 'es2022', 'es2023', 'esnext', 'dom', 'dom.iterable', 'webworker', 'webworker.importscripts', 'webworker.iterable', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory', 'es2017.string', 'es2017.intl', 'es2017.typedarrays', 'es2018.asyncgenerator', 'es2018.asynciterable', 'es2018.intl', 'es2018.promise', 'es2018.regexp', 'es2019.array', 'es2019.object', 'es2019.string', 'es2019.symbol', 'es2019.intl', 'es2020.bigint', 'es2020.date', 'es2020.promise', 'es2020.sharedmemory', 'es2020.string', 'es2020.symbol.wellknown', 'es2020.intl', 'es2020.number', 'es2021.promise', 'es2021.string', 'es2021.weakref', 'es2021.intl', 'es2022.array', 'es2022.error', 'es2022.intl', 'es2022.object', 'es2022.sharedmemory', 'es2022.string', 'es2022.regexp', 'es2023.array', 'esnext.array', 'esnext.symbol', 'esnext.asynciterable', 'esnext.intl', 'esnext.bigint', 'esnext.string', 'esnext.promise', 'esnext.weakref', 'decorators', 'decorators.legacy'. +error TS6046: Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'es2018', 'es2019', 'es2020', 'es2021', 'es2022', 'es2023', 'esnext', 'dom', 'dom.iterable', 'webworker', 'webworker.importscripts', 'webworker.iterable', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory', 'es2017.string', 'es2017.intl', 'es2017.typedarrays', 'es2018.asyncgenerator', 'es2018.asynciterable', 'es2018.intl', 'es2018.promise', 'es2018.regexp', 'es2019.array', 'es2019.object', 'es2019.string', 'es2019.symbol', 'es2019.intl', 'es2020.bigint', 'es2020.date', 'es2020.promise', 'es2020.sharedmemory', 'es2020.string', 'es2020.symbol.wellknown', 'es2020.intl', 'es2020.number', 'es2021.promise', 'es2021.string', 'es2021.weakref', 'es2021.intl', 'es2022.array', 'es2022.error', 'es2022.intl', 'es2022.object', 'es2022.sharedmemory', 'es2022.string', 'es2022.regexp', 'es2023.array', 'es2023.collection', 'esnext.array', 'esnext.collection', 'esnext.symbol', 'esnext.asynciterable', 'esnext.intl', 'esnext.bigint', 'esnext.string', 'esnext.promise', 'esnext.weakref', 'decorators', 'decorators.legacy'. diff --git a/tests/baselines/reference/config/commandLineParsing/parseCommandLine/Parse --lib option with trailing white-space.js b/tests/baselines/reference/config/commandLineParsing/parseCommandLine/Parse --lib option with trailing white-space.js index a0d83c38d378d..7fffd6f7e1ba4 100644 --- a/tests/baselines/reference/config/commandLineParsing/parseCommandLine/Parse --lib option with trailing white-space.js +++ b/tests/baselines/reference/config/commandLineParsing/parseCommandLine/Parse --lib option with trailing white-space.js @@ -10,4 +10,4 @@ WatchOptions:: FileNames:: es7,0.ts Errors:: -error TS6046: Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'es2018', 'es2019', 'es2020', 'es2021', 'es2022', 'es2023', 'esnext', 'dom', 'dom.iterable', 'webworker', 'webworker.importscripts', 'webworker.iterable', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory', 'es2017.string', 'es2017.intl', 'es2017.typedarrays', 'es2018.asyncgenerator', 'es2018.asynciterable', 'es2018.intl', 'es2018.promise', 'es2018.regexp', 'es2019.array', 'es2019.object', 'es2019.string', 'es2019.symbol', 'es2019.intl', 'es2020.bigint', 'es2020.date', 'es2020.promise', 'es2020.sharedmemory', 'es2020.string', 'es2020.symbol.wellknown', 'es2020.intl', 'es2020.number', 'es2021.promise', 'es2021.string', 'es2021.weakref', 'es2021.intl', 'es2022.array', 'es2022.error', 'es2022.intl', 'es2022.object', 'es2022.sharedmemory', 'es2022.string', 'es2022.regexp', 'es2023.array', 'esnext.array', 'esnext.symbol', 'esnext.asynciterable', 'esnext.intl', 'esnext.bigint', 'esnext.string', 'esnext.promise', 'esnext.weakref', 'decorators', 'decorators.legacy'. +error TS6046: Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'es2018', 'es2019', 'es2020', 'es2021', 'es2022', 'es2023', 'esnext', 'dom', 'dom.iterable', 'webworker', 'webworker.importscripts', 'webworker.iterable', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory', 'es2017.string', 'es2017.intl', 'es2017.typedarrays', 'es2018.asyncgenerator', 'es2018.asynciterable', 'es2018.intl', 'es2018.promise', 'es2018.regexp', 'es2019.array', 'es2019.object', 'es2019.string', 'es2019.symbol', 'es2019.intl', 'es2020.bigint', 'es2020.date', 'es2020.promise', 'es2020.sharedmemory', 'es2020.string', 'es2020.symbol.wellknown', 'es2020.intl', 'es2020.number', 'es2021.promise', 'es2021.string', 'es2021.weakref', 'es2021.intl', 'es2022.array', 'es2022.error', 'es2022.intl', 'es2022.object', 'es2022.sharedmemory', 'es2022.string', 'es2022.regexp', 'es2023.array', 'es2023.collection', 'esnext.array', 'esnext.collection', 'esnext.symbol', 'esnext.asynciterable', 'esnext.intl', 'esnext.bigint', 'esnext.string', 'esnext.promise', 'esnext.weakref', 'decorators', 'decorators.legacy'. diff --git a/tests/baselines/reference/config/commandLineParsing/parseCommandLine/Parse invalid option of library flags.js b/tests/baselines/reference/config/commandLineParsing/parseCommandLine/Parse invalid option of library flags.js index 3309e00f86fcf..15739b887561e 100644 --- a/tests/baselines/reference/config/commandLineParsing/parseCommandLine/Parse invalid option of library flags.js +++ b/tests/baselines/reference/config/commandLineParsing/parseCommandLine/Parse invalid option of library flags.js @@ -10,4 +10,4 @@ WatchOptions:: FileNames:: 0.ts Errors:: -error TS6046: Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'es2018', 'es2019', 'es2020', 'es2021', 'es2022', 'es2023', 'esnext', 'dom', 'dom.iterable', 'webworker', 'webworker.importscripts', 'webworker.iterable', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory', 'es2017.string', 'es2017.intl', 'es2017.typedarrays', 'es2018.asyncgenerator', 'es2018.asynciterable', 'es2018.intl', 'es2018.promise', 'es2018.regexp', 'es2019.array', 'es2019.object', 'es2019.string', 'es2019.symbol', 'es2019.intl', 'es2020.bigint', 'es2020.date', 'es2020.promise', 'es2020.sharedmemory', 'es2020.string', 'es2020.symbol.wellknown', 'es2020.intl', 'es2020.number', 'es2021.promise', 'es2021.string', 'es2021.weakref', 'es2021.intl', 'es2022.array', 'es2022.error', 'es2022.intl', 'es2022.object', 'es2022.sharedmemory', 'es2022.string', 'es2022.regexp', 'es2023.array', 'esnext.array', 'esnext.symbol', 'esnext.asynciterable', 'esnext.intl', 'esnext.bigint', 'esnext.string', 'esnext.promise', 'esnext.weakref', 'decorators', 'decorators.legacy'. +error TS6046: Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'es2018', 'es2019', 'es2020', 'es2021', 'es2022', 'es2023', 'esnext', 'dom', 'dom.iterable', 'webworker', 'webworker.importscripts', 'webworker.iterable', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory', 'es2017.string', 'es2017.intl', 'es2017.typedarrays', 'es2018.asyncgenerator', 'es2018.asynciterable', 'es2018.intl', 'es2018.promise', 'es2018.regexp', 'es2019.array', 'es2019.object', 'es2019.string', 'es2019.symbol', 'es2019.intl', 'es2020.bigint', 'es2020.date', 'es2020.promise', 'es2020.sharedmemory', 'es2020.string', 'es2020.symbol.wellknown', 'es2020.intl', 'es2020.number', 'es2021.promise', 'es2021.string', 'es2021.weakref', 'es2021.intl', 'es2022.array', 'es2022.error', 'es2022.intl', 'es2022.object', 'es2022.sharedmemory', 'es2022.string', 'es2022.regexp', 'es2023.array', 'es2023.collection', 'esnext.array', 'esnext.collection', 'esnext.symbol', 'esnext.asynciterable', 'esnext.intl', 'esnext.bigint', 'esnext.string', 'esnext.promise', 'esnext.weakref', 'decorators', 'decorators.legacy'. diff --git a/tests/baselines/reference/esNextWeakRefs_IterableWeakMap.types b/tests/baselines/reference/esNextWeakRefs_IterableWeakMap.types index 79e54575127f7..8fef081a31926 100644 --- a/tests/baselines/reference/esNextWeakRefs_IterableWeakMap.types +++ b/tests/baselines/reference/esNextWeakRefs_IterableWeakMap.types @@ -130,10 +130,10 @@ export class IterableWeakMap implements WeakMap { this.#finalizationGroup.register(key, { >this.#finalizationGroup.register(key, { set: this.#refSet, ref, }, ref) : void ->this.#finalizationGroup.register : (target: object, heldValue: { readonly ref: WeakRef; readonly set: Set>; }, unregisterToken?: object | undefined) => void +>this.#finalizationGroup.register : (target: WeakKey, heldValue: { readonly ref: WeakRef; readonly set: Set>; }, unregisterToken?: WeakKey | undefined) => void >this.#finalizationGroup : FinalizationRegistry<{ readonly ref: WeakRef; readonly set: Set>; }> >this : this ->register : (target: object, heldValue: { readonly ref: WeakRef; readonly set: Set>; }, unregisterToken?: object | undefined) => void +>register : (target: WeakKey, heldValue: { readonly ref: WeakRef; readonly set: Set>; }, unregisterToken?: WeakKey | undefined) => void >key : K >{ set: this.#refSet, ref, } : { set: Set>; ref: WeakRef; } @@ -224,10 +224,10 @@ export class IterableWeakMap implements WeakMap { this.#finalizationGroup.unregister(ref); >this.#finalizationGroup.unregister(ref) : void ->this.#finalizationGroup.unregister : (unregisterToken: object) => void +>this.#finalizationGroup.unregister : (unregisterToken: WeakKey) => void >this.#finalizationGroup : FinalizationRegistry<{ readonly ref: WeakRef; readonly set: Set>; }> >this : this ->unregister : (unregisterToken: object) => void +>unregister : (unregisterToken: WeakKey) => void >ref : WeakRef return true; diff --git a/tests/baselines/reference/tsc/runWithoutArgs/does-not-add-color-when-NO_COLOR-is-set.js b/tests/baselines/reference/tsc/runWithoutArgs/does-not-add-color-when-NO_COLOR-is-set.js index cbee6ce837d1d..9b83f36bb840d 100644 --- a/tests/baselines/reference/tsc/runWithoutArgs/does-not-add-color-when-NO_COLOR-is-set.js +++ b/tests/baselines/reference/tsc/runWithoutArgs/does-not-add-color-when-NO_COLOR-is-set.js @@ -110,7 +110,7 @@ default: undefined --lib Specify a set of bundled library declaration files that describe the target runtime environment. -one or more: es5, es6/es2015, es7/es2016, es2017, es2018, es2019, es2020, es2021, es2022, es2023, esnext, dom, dom.iterable, webworker, webworker.importscripts, webworker.iterable, scripthost, es2015.core, es2015.collection, es2015.generator, es2015.iterable, es2015.promise, es2015.proxy, es2015.reflect, es2015.symbol, es2015.symbol.wellknown, es2016.array.include, es2017.object, es2017.sharedmemory, es2017.string, es2017.intl, es2017.typedarrays, es2018.asyncgenerator, es2018.asynciterable/esnext.asynciterable, es2018.intl, es2018.promise, es2018.regexp, es2019.array, es2019.object, es2019.string, es2019.symbol/esnext.symbol, es2019.intl, es2020.bigint/esnext.bigint, es2020.date, es2020.promise, es2020.sharedmemory, es2020.string, es2020.symbol.wellknown, es2020.intl, es2020.number, es2021.promise/esnext.promise, es2021.string, es2021.weakref/esnext.weakref, es2021.intl, es2022.array, es2022.error, es2022.intl, es2022.object, es2022.sharedmemory, es2022.string/esnext.string, es2022.regexp, es2023.array/esnext.array, esnext.intl, decorators, decorators.legacy +one or more: es5, es6/es2015, es7/es2016, es2017, es2018, es2019, es2020, es2021, es2022, es2023, esnext, dom, dom.iterable, webworker, webworker.importscripts, webworker.iterable, scripthost, es2015.core, es2015.collection, es2015.generator, es2015.iterable, es2015.promise, es2015.proxy, es2015.reflect, es2015.symbol, es2015.symbol.wellknown, es2016.array.include, es2017.object, es2017.sharedmemory, es2017.string, es2017.intl, es2017.typedarrays, es2018.asyncgenerator, es2018.asynciterable/esnext.asynciterable, es2018.intl, es2018.promise, es2018.regexp, es2019.array, es2019.object, es2019.string, es2019.symbol/esnext.symbol, es2019.intl, es2020.bigint/esnext.bigint, es2020.date, es2020.promise, es2020.sharedmemory, es2020.string, es2020.symbol.wellknown, es2020.intl, es2020.number, es2021.promise/esnext.promise, es2021.string, es2021.weakref/esnext.weakref, es2021.intl, es2022.array, es2022.error, es2022.intl, es2022.object, es2022.sharedmemory, es2022.string/esnext.string, es2022.regexp, es2023.array/esnext.array, es2023.collection/esnext.collection, esnext.intl, decorators, decorators.legacy default: undefined --allowJs diff --git a/tests/baselines/reference/tsc/runWithoutArgs/show-help-with-ExitStatus.DiagnosticsPresent_OutputsSkipped-when-host-can't-provide-terminal-width.js b/tests/baselines/reference/tsc/runWithoutArgs/show-help-with-ExitStatus.DiagnosticsPresent_OutputsSkipped-when-host-can't-provide-terminal-width.js index 37c7be1aeed5e..ed303f56847b5 100644 --- a/tests/baselines/reference/tsc/runWithoutArgs/show-help-with-ExitStatus.DiagnosticsPresent_OutputsSkipped-when-host-can't-provide-terminal-width.js +++ b/tests/baselines/reference/tsc/runWithoutArgs/show-help-with-ExitStatus.DiagnosticsPresent_OutputsSkipped-when-host-can't-provide-terminal-width.js @@ -110,7 +110,7 @@ default: undefined --lib Specify a set of bundled library declaration files that describe the target runtime environment. -one or more: es5, es6/es2015, es7/es2016, es2017, es2018, es2019, es2020, es2021, es2022, es2023, esnext, dom, dom.iterable, webworker, webworker.importscripts, webworker.iterable, scripthost, es2015.core, es2015.collection, es2015.generator, es2015.iterable, es2015.promise, es2015.proxy, es2015.reflect, es2015.symbol, es2015.symbol.wellknown, es2016.array.include, es2017.object, es2017.sharedmemory, es2017.string, es2017.intl, es2017.typedarrays, es2018.asyncgenerator, es2018.asynciterable/esnext.asynciterable, es2018.intl, es2018.promise, es2018.regexp, es2019.array, es2019.object, es2019.string, es2019.symbol/esnext.symbol, es2019.intl, es2020.bigint/esnext.bigint, es2020.date, es2020.promise, es2020.sharedmemory, es2020.string, es2020.symbol.wellknown, es2020.intl, es2020.number, es2021.promise/esnext.promise, es2021.string, es2021.weakref/esnext.weakref, es2021.intl, es2022.array, es2022.error, es2022.intl, es2022.object, es2022.sharedmemory, es2022.string/esnext.string, es2022.regexp, es2023.array/esnext.array, esnext.intl, decorators, decorators.legacy +one or more: es5, es6/es2015, es7/es2016, es2017, es2018, es2019, es2020, es2021, es2022, es2023, esnext, dom, dom.iterable, webworker, webworker.importscripts, webworker.iterable, scripthost, es2015.core, es2015.collection, es2015.generator, es2015.iterable, es2015.promise, es2015.proxy, es2015.reflect, es2015.symbol, es2015.symbol.wellknown, es2016.array.include, es2017.object, es2017.sharedmemory, es2017.string, es2017.intl, es2017.typedarrays, es2018.asyncgenerator, es2018.asynciterable/esnext.asynciterable, es2018.intl, es2018.promise, es2018.regexp, es2019.array, es2019.object, es2019.string, es2019.symbol/esnext.symbol, es2019.intl, es2020.bigint/esnext.bigint, es2020.date, es2020.promise, es2020.sharedmemory, es2020.string, es2020.symbol.wellknown, es2020.intl, es2020.number, es2021.promise/esnext.promise, es2021.string, es2021.weakref/esnext.weakref, es2021.intl, es2022.array, es2022.error, es2022.intl, es2022.object, es2022.sharedmemory, es2022.string/esnext.string, es2022.regexp, es2023.array/esnext.array, es2023.collection/esnext.collection, esnext.intl, decorators, decorators.legacy default: undefined --allowJs diff --git a/tests/baselines/reference/tsc/runWithoutArgs/show-help-with-ExitStatus.DiagnosticsPresent_OutputsSkipped.js b/tests/baselines/reference/tsc/runWithoutArgs/show-help-with-ExitStatus.DiagnosticsPresent_OutputsSkipped.js index 37c7be1aeed5e..ed303f56847b5 100644 --- a/tests/baselines/reference/tsc/runWithoutArgs/show-help-with-ExitStatus.DiagnosticsPresent_OutputsSkipped.js +++ b/tests/baselines/reference/tsc/runWithoutArgs/show-help-with-ExitStatus.DiagnosticsPresent_OutputsSkipped.js @@ -110,7 +110,7 @@ default: undefined --lib Specify a set of bundled library declaration files that describe the target runtime environment. -one or more: es5, es6/es2015, es7/es2016, es2017, es2018, es2019, es2020, es2021, es2022, es2023, esnext, dom, dom.iterable, webworker, webworker.importscripts, webworker.iterable, scripthost, es2015.core, es2015.collection, es2015.generator, es2015.iterable, es2015.promise, es2015.proxy, es2015.reflect, es2015.symbol, es2015.symbol.wellknown, es2016.array.include, es2017.object, es2017.sharedmemory, es2017.string, es2017.intl, es2017.typedarrays, es2018.asyncgenerator, es2018.asynciterable/esnext.asynciterable, es2018.intl, es2018.promise, es2018.regexp, es2019.array, es2019.object, es2019.string, es2019.symbol/esnext.symbol, es2019.intl, es2020.bigint/esnext.bigint, es2020.date, es2020.promise, es2020.sharedmemory, es2020.string, es2020.symbol.wellknown, es2020.intl, es2020.number, es2021.promise/esnext.promise, es2021.string, es2021.weakref/esnext.weakref, es2021.intl, es2022.array, es2022.error, es2022.intl, es2022.object, es2022.sharedmemory, es2022.string/esnext.string, es2022.regexp, es2023.array/esnext.array, esnext.intl, decorators, decorators.legacy +one or more: es5, es6/es2015, es7/es2016, es2017, es2018, es2019, es2020, es2021, es2022, es2023, esnext, dom, dom.iterable, webworker, webworker.importscripts, webworker.iterable, scripthost, es2015.core, es2015.collection, es2015.generator, es2015.iterable, es2015.promise, es2015.proxy, es2015.reflect, es2015.symbol, es2015.symbol.wellknown, es2016.array.include, es2017.object, es2017.sharedmemory, es2017.string, es2017.intl, es2017.typedarrays, es2018.asyncgenerator, es2018.asynciterable/esnext.asynciterable, es2018.intl, es2018.promise, es2018.regexp, es2019.array, es2019.object, es2019.string, es2019.symbol/esnext.symbol, es2019.intl, es2020.bigint/esnext.bigint, es2020.date, es2020.promise, es2020.sharedmemory, es2020.string, es2020.symbol.wellknown, es2020.intl, es2020.number, es2021.promise/esnext.promise, es2021.string, es2021.weakref/esnext.weakref, es2021.intl, es2022.array, es2022.error, es2022.intl, es2022.object, es2022.sharedmemory, es2022.string/esnext.string, es2022.regexp, es2023.array/esnext.array, es2023.collection/esnext.collection, esnext.intl, decorators, decorators.legacy default: undefined --allowJs diff --git a/tests/cases/compiler/acceptSymbolAsWeakType.ts b/tests/cases/compiler/acceptSymbolAsWeakType.ts index 53f8ea5ff0ead..59dbdb4cd83e0 100644 --- a/tests/cases/compiler/acceptSymbolAsWeakType.ts +++ b/tests/cases/compiler/acceptSymbolAsWeakType.ts @@ -18,6 +18,6 @@ wm.delete(s); const wr = new WeakRef(s); wr.deref(); -const f = new FinalizationRegistry(() => {}); +const f = new FinalizationRegistry(() => {}); f.register(s, null); f.unregister(s); \ No newline at end of file