Skip to content

Commit 5c65e41

Browse files
committed
Fix Symbols
1 parent ae13b8d commit 5c65e41

File tree

2 files changed

+13
-19
lines changed

2 files changed

+13
-19
lines changed

packages/core-js-types/src/base/pure/proposals/symbol.d.ts

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
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
@@ -33,24 +32,20 @@
3332
// License: https://github.com/microsoft/TypeScript/blob/v5.9.3/LICENSE.txt
3433

3534
declare 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 {

tests/type-definitions/pure/proposals/await-dictionary.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import promiseAllKeyed from '@core-js/pure/full/promise/all-keyed';
22
import promiseAllSettledKeyed from '@core-js/pure/full/promise/all-settled-keyed';
33
import promiseResolve from '@core-js/pure/full/promise/resolve';
4-
import $Symbol from '@core-js/pure/full/symbol';
54
import { CoreJSPromiseAndPromiseLike } from '../../helpers';
65

76
const res: CoreJSPromiseAndPromiseLike<{ a: number, b: string, c: boolean }> = promiseAllKeyed({
@@ -10,7 +9,7 @@ const res: CoreJSPromiseAndPromiseLike<{ a: number, b: string, c: boolean }> = p
109
c: promiseResolve(true),
1110
});
1211

13-
const sym = $Symbol('sym');
12+
declare const sym: unique symbol;
1413
const res2: CoreJSPromiseAndPromiseLike<{ [sym]: number }> = promiseAllKeyed({
1514
[sym]: promiseResolve(1)
1615
});

0 commit comments

Comments
 (0)