1- // Motivation: We should use SymbolConstructor without asyncIterator, matchAll, dispose, asyncDispose,
2- // customMatcher, metadata properties to avoid signature conflicts
1+ // Motivation: We should use all unique symbols in SymbolConstructor with fallback
32
43// proposal stage: 3
54// https://github.com/tc39/proposal-explicit-resource-management
3332// License: https://github.com/microsoft/TypeScript/blob/v5.9.3/LICENSE.txt
3433
3534declare namespace CoreJS {
36- type BaseSymbolConstructor = {
37- ( description ?: string | number | symbol ) : symbol ;
38- new ( description ?: string | number | symbol ) : symbol ;
39- } & Omit <
40- SymbolConstructor ,
41- 'asyncIterator' | 'matchAll' | 'dispose' | 'asyncDispose' | 'customMatcher' | 'metadata'
42- > ;
43-
44- export interface CoreJSSymbolConstructor extends BaseSymbolConstructor {
35+ const CoreJSFallbackSymbol : unique symbol ;
36+ type CoreJSFallbackSymbolType = typeof CoreJSFallbackSymbol ;
37+ type GetNativeWithFallback < T , K extends PropertyKey > = K extends keyof T ? T [ K ] : CoreJSFallbackSymbolType ;
38+
39+ export interface CoreJSSymbolConstructor extends SymbolConstructor {
4540 /**
4641 * A method that is used to release resources held by an object. Called by the semantics of the `using` statement.
4742 */
48- readonly dispose : unique symbol ;
43+ readonly dispose : GetNativeWithFallback < SymbolConstructor , 'dispose' > ;
4944
5045 /**
5146 * A method that is used to asynchronously release resources held by an object. Called by the semantics of the `await using` statement.
5247 */
53- readonly asyncDispose : unique symbol ;
48+ readonly asyncDispose : GetNativeWithFallback < SymbolConstructor , 'asyncDispose' > ;
5449
5550 /**
5651 * Determines whether the given value is a registered symbol.
@@ -68,13 +63,13 @@ declare namespace CoreJS {
6863 * A method that returns the default async iterator for an object. Called by the semantics of
6964 * the for-await-of statement.
7065 */
71- readonly asyncIterator : unique symbol ;
66+ readonly asyncIterator : GetNativeWithFallback < SymbolConstructor , 'asyncIterator' > ;
7267
73- readonly customMatcher : unique symbol ;
68+ readonly customMatcher : GetNativeWithFallback < SymbolConstructor , 'customMatcher' > ;
7469
75- readonly metadata : unique symbol ;
70+ readonly metadata : GetNativeWithFallback < SymbolConstructor , 'metadata' > ;
7671
77- readonly matchAll : unique symbol ;
72+ readonly matchAll : GetNativeWithFallback < SymbolConstructor , 'matchAll' > ;
7873 }
7974
8075 export interface CoreJSSymbol extends Symbol {
0 commit comments