Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
3bac33d
Update 2021 weakref types
leoelm Feb 9, 2023
5871e83
Add symbol to WeakRef and FinalizationRegistry
leoelm Feb 9, 2023
c0161d9
Update WeakSet keys
leoelm Mar 5, 2023
0596a4c
Add WeakMap symbol support
leoelm Mar 5, 2023
776c6a7
Resolve compilation and testing issues
leoelm Mar 14, 2023
4b02a2c
Add some test changes
leoelm Mar 16, 2023
0e809bf
Add testing for WeakRef and FinalizationRegistry
leoelm Mar 22, 2023
2241306
Undo lib changes
leoelm Mar 23, 2023
18ec290
Undo lib changes
leoelm Mar 23, 2023
0198657
Address PR comments
leoelm Mar 29, 2023
a103a0b
Update 2021 weakref types
leoelm Feb 9, 2023
e898ad0
Add symbol to WeakRef and FinalizationRegistry
leoelm Feb 9, 2023
8b90d0a
Update WeakSet keys
leoelm Mar 5, 2023
485aea5
Add WeakMap symbol support
leoelm Mar 5, 2023
6350617
Resolve compilation and testing issues
leoelm Mar 14, 2023
b1a8c37
Add some test changes
leoelm Mar 16, 2023
8413425
Add testing for WeakRef and FinalizationRegistry
leoelm Mar 22, 2023
f8470f1
Undo lib changes
leoelm Mar 23, 2023
ff83b5c
Undo lib changes
leoelm Mar 23, 2023
c3275ca
Address PR comments
leoelm Mar 29, 2023
0809ac2
Merge branch 'le/symbols-as-weak-map-keys' of github.com:leoelm/TypeS…
leoelm Mar 29, 2023
8c2fd56
Address PR comments
leoelm Apr 3, 2023
2eb0354
Add baselines
leoelm Apr 3, 2023
7563f5e
Address PR comments
leoelm Apr 5, 2023
71b47cb
Address PR comments
leoelm Apr 6, 2023
c966981
Merge branch 'le/symbol-as-weak-keys' into le/symbols-as-weak-map-keys
leoelm Apr 8, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Address PR comments
  • Loading branch information
leoelm committed Apr 5, 2023
commit 7563f5e7670289844fc880bbc84fe38102cd14de
10 changes: 5 additions & 5 deletions src/lib/es2015.collection.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@ interface WeakMap<K extends WeakKey, V> {
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 <K extends object = object, V = any>(entries?: readonly [K, V][] | null): WeakMap<K, V>;
readonly prototype: WeakMap<object, any>;
new <K extends WeakKey = WeakKey, V = any>(entries?: readonly [K, V][] | null): WeakMap<K, V>;
readonly prototype: WeakMap<WeakKey, any>;
}
declare var WeakMap: WeakMapConstructor;

Expand Down Expand Up @@ -109,7 +109,7 @@ interface ReadonlySet<T> {

interface WeakSet<T extends WeakKey> {
/**
* Appends a new object to the end of the WeakSet.
* Appends a new value to the end of the WeakSet.
*/
add(value: T): this;
/**
Expand All @@ -118,7 +118,7 @@ interface WeakSet<T extends WeakKey> {
*/
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;
}
Expand Down
15 changes: 6 additions & 9 deletions tests/baselines/reference/acceptSymbolAsWeakType.errors.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
tests/cases/compiler/acceptSymbolAsWeakType.ts(18,3): error TS2339: Property 'registerSymbol' does not exist on type 'FinalizationRegistry<symbol>'.
tests/cases/compiler/acceptSymbolAsWeakType.ts(19,3): error TS2339: Property 'unregisterSymbol' does not exist on type 'FinalizationRegistry<symbol>'.
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]);
Expand All @@ -20,9 +19,7 @@ tests/cases/compiler/acceptSymbolAsWeakType.ts(19,3): error TS2339: Property 'un
wr.deref();

const f = new FinalizationRegistry<symbol>(() => {});
f.registerSymbol(s, null);
~~~~~~~~~~~~~~
!!! error TS2339: Property 'registerSymbol' does not exist on type 'FinalizationRegistry<symbol>'.
f.unregisterSymbol(s);
~~~~~~~~~~~~~~~~
!!! error TS2339: Property 'unregisterSymbol' does not exist on type 'FinalizationRegistry<symbol>'.
f.register(s, null);
~~~~
!!! error TS2345: Argument of type 'null' is not assignable to parameter of type 'symbol'.
f.unregister(s);
9 changes: 5 additions & 4 deletions tests/baselines/reference/acceptSymbolAsWeakType.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ const wr = new WeakRef(s);
wr.deref();

const f = new FinalizationRegistry<symbol>(() => {});
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);
Expand All @@ -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);
8 changes: 6 additions & 2 deletions tests/baselines/reference/acceptSymbolAsWeakType.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,15 @@ const f = new FinalizationRegistry<symbol>(() => {});
>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))

28 changes: 14 additions & 14 deletions tests/baselines/reference/acceptSymbolAsWeakType.types
Original file line number Diff line number Diff line change
Expand Up @@ -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<symbol, boolean>
>get : (key: symbol) => boolean
>get : (key: symbol) => boolean | undefined
>s : symbol

wm.delete(s);
Expand All @@ -78,29 +78,29 @@ 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<symbol>
>deref : () => symbol
>deref : () => symbol | undefined

const f = new FinalizationRegistry<symbol>(() => {});
>f : FinalizationRegistry<symbol>
>new FinalizationRegistry<symbol>(() => {}) : FinalizationRegistry<symbol>
>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<symbol>
>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<symbol>
>unregisterSymbol : any
>unregister : (unregisterToken: WeakKey) => void
>s : symbol

5 changes: 3 additions & 2 deletions tests/cases/compiler/acceptSymbolAsWeakType.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @strict: true
// @lib: esnext
// @target: esnext

Expand All @@ -18,5 +19,5 @@ const wr = new WeakRef(s);
wr.deref();

const f = new FinalizationRegistry<symbol>(() => {});
f.registerSymbol(s, null);
f.unregisterSymbol(s);
f.register(s, null);
f.unregister(s);