-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Type definitions for 'Symbols as WeakMap keys' #52534
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
If 'contributions are welcome', there are developers at Bloomberg ready and standing by to contribute a PR. |
@leoelm from @bloomberg has begun looking into the changes required for this. |
We discussed this in a design meeting recently. Even though the proposal makes an exception for registered symbols from |
Hello all, We have identified a complexity in regards to adding type support for the primitive symbol to The problem originates from the change being to the constraint of a generic, which is not something interface merging supports. Illustrated at the example of ES2015 : interface WeakSet<T extends object> {
...
} ES2023: interface WeakSet<T extends object | symbol> {
...
}
// Error! All declarations of 'WeakSet' must have identical type parameters.(2428) The above addition in ES2023 would now lead to an invalid redefinition of the interface Proposed SolutionIntroduce a custom defined type to ES2015 based on an interface that can be augmented to include ES2015: /**
* This type is used to 'store' the types that can be used with Weak{Map,Set,Ref}
* es2022
**/
interface AllowableWeakTypesStore {
object: object;
}
type AllowableWeakTypes = AllowableWeakTypesStore[keyof AllowableWeakTypesStore];
interface WeakSet<T extends (AllowableWeakTypes & {})> {
...
} ES2023: interface AllowableWeakTypesStore {
symbol: symbol;
} Alternative Solution (not favoured)
/// <reference no-default-lib="true"/>
/// <reference lib="es2022.exceptweak" />
interface WeakRef<T extends object | symbol> {
...
} We discarded this since it requires duplicating the definitions for Any thoughts or alternative approaches are greatly appreciated! Thank you in advance! |
The solution we use for |
@rbuckton Somehow off topic, but I would like to see |
@acutmore, @leoelm: Is bloomberg#76 ready for a PR? It looks pretty much like what I would have written given my earlier suggestion. |
Hi @rbuckton, thanks for taking a look at bloomberg#76. We've merged that now. I'll sync up with @leoelm and hopefully we'll get the PR to Microsoft open tomorrow. |
lib Update Request for 'Symbols as WeakMap keys'
Configuration Check
My compilation target is
ESNext
and my lib isthe default
.Missing / Incorrect Definition
Symbols as WeakMap keys went to stage 4 at TC39 yesterday.
The types for
WeakMap
,WeakSet
,WeakRef
andFinalizationRegistry
can be updated to reflect thatsymbol
is now also allowed alongside the existingobject
constraint.Sample Code
Documentation Link
https://github.com/tc39/proposal-symbols-as-weakmap-keys
The text was updated successfully, but these errors were encountered: