From c32d87f3d817442e34aa32e623bb8ebfc103a358 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Thu, 5 Oct 2023 15:49:10 -0700 Subject: [PATCH 1/2] Add tests --- tests/baselines/reference/issue55901.js | 40 +++++++++++++++ tests/baselines/reference/issue55901.symbols | 46 +++++++++++++++++ tests/baselines/reference/issue55901.types | 52 ++++++++++++++++++++ tests/cases/compiler/issue55901.ts | 15 ++++++ 4 files changed, 153 insertions(+) create mode 100644 tests/baselines/reference/issue55901.js create mode 100644 tests/baselines/reference/issue55901.symbols create mode 100644 tests/baselines/reference/issue55901.types create mode 100644 tests/cases/compiler/issue55901.ts diff --git a/tests/baselines/reference/issue55901.js b/tests/baselines/reference/issue55901.js new file mode 100644 index 0000000000000..4eeffc30f46f9 --- /dev/null +++ b/tests/baselines/reference/issue55901.js @@ -0,0 +1,40 @@ +//// [tests/cases/compiler/issue55901.ts] //// + +//// [issue55901.ts] +export const l = "A"; +export const l1 = l as typeof l; +export const l2 = l; +export let l3 = l as typeof l; +export let a4 = l; + +export const s = Symbol(); +export const s1 = s as typeof s; +export const s2 = s; +export let s3 = s as typeof s; +export let s4 = s; + + +//// [issue55901.js] +export const l = "A"; +export const l1 = l; +export const l2 = l; +export let l3 = l; +export let a4 = l; +export const s = Symbol(); +export const s1 = s; +export const s2 = s; +export let s3 = s; +export let s4 = s; + + +//// [issue55901.d.ts] +export declare const l = "A"; +export declare const l1: "A"; +export declare const l2 = "A"; +export declare let l3: "A"; +export declare let a4: string; +export declare const s: unique symbol; +export declare const s1: symbol; +export declare const s2: symbol; +export declare let s3: symbol; +export declare let s4: symbol; diff --git a/tests/baselines/reference/issue55901.symbols b/tests/baselines/reference/issue55901.symbols new file mode 100644 index 0000000000000..4cbf12497190e --- /dev/null +++ b/tests/baselines/reference/issue55901.symbols @@ -0,0 +1,46 @@ +//// [tests/cases/compiler/issue55901.ts] //// + +=== issue55901.ts === +export const l = "A"; +>l : Symbol(l, Decl(issue55901.ts, 0, 12)) + +export const l1 = l as typeof l; +>l1 : Symbol(l1, Decl(issue55901.ts, 1, 12)) +>l : Symbol(l, Decl(issue55901.ts, 0, 12)) +>l : Symbol(l, Decl(issue55901.ts, 0, 12)) + +export const l2 = l; +>l2 : Symbol(l2, Decl(issue55901.ts, 2, 12)) +>l : Symbol(l, Decl(issue55901.ts, 0, 12)) + +export let l3 = l as typeof l; +>l3 : Symbol(l3, Decl(issue55901.ts, 3, 10)) +>l : Symbol(l, Decl(issue55901.ts, 0, 12)) +>l : Symbol(l, Decl(issue55901.ts, 0, 12)) + +export let a4 = l; +>a4 : Symbol(a4, Decl(issue55901.ts, 4, 10)) +>l : Symbol(l, Decl(issue55901.ts, 0, 12)) + +export const s = Symbol(); +>s : Symbol(s, Decl(issue55901.ts, 6, 12)) +>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, --, --)) + +export const s1 = s as typeof s; +>s1 : Symbol(s1, Decl(issue55901.ts, 7, 12)) +>s : Symbol(s, Decl(issue55901.ts, 6, 12)) +>s : Symbol(s, Decl(issue55901.ts, 6, 12)) + +export const s2 = s; +>s2 : Symbol(s2, Decl(issue55901.ts, 8, 12)) +>s : Symbol(s, Decl(issue55901.ts, 6, 12)) + +export let s3 = s as typeof s; +>s3 : Symbol(s3, Decl(issue55901.ts, 9, 10)) +>s : Symbol(s, Decl(issue55901.ts, 6, 12)) +>s : Symbol(s, Decl(issue55901.ts, 6, 12)) + +export let s4 = s; +>s4 : Symbol(s4, Decl(issue55901.ts, 10, 10)) +>s : Symbol(s, Decl(issue55901.ts, 6, 12)) + diff --git a/tests/baselines/reference/issue55901.types b/tests/baselines/reference/issue55901.types new file mode 100644 index 0000000000000..11b3111bb7ee0 --- /dev/null +++ b/tests/baselines/reference/issue55901.types @@ -0,0 +1,52 @@ +//// [tests/cases/compiler/issue55901.ts] //// + +=== issue55901.ts === +export const l = "A"; +>l : "A" +>"A" : "A" + +export const l1 = l as typeof l; +>l1 : "A" +>l as typeof l : "A" +>l : "A" +>l : "A" + +export const l2 = l; +>l2 : "A" +>l : "A" + +export let l3 = l as typeof l; +>l3 : "A" +>l as typeof l : "A" +>l : "A" +>l : "A" + +export let a4 = l; +>a4 : string +>l : "A" + +export const s = Symbol(); +>s : unique symbol +>Symbol() : unique symbol +>Symbol : SymbolConstructor + +export const s1 = s as typeof s; +>s1 : symbol +>s as typeof s : unique symbol +>s : unique symbol +>s : unique symbol + +export const s2 = s; +>s2 : symbol +>s : unique symbol + +export let s3 = s as typeof s; +>s3 : symbol +>s as typeof s : unique symbol +>s : unique symbol +>s : unique symbol + +export let s4 = s; +>s4 : symbol +>s : unique symbol + diff --git a/tests/cases/compiler/issue55901.ts b/tests/cases/compiler/issue55901.ts new file mode 100644 index 0000000000000..a6b240af3f269 --- /dev/null +++ b/tests/cases/compiler/issue55901.ts @@ -0,0 +1,15 @@ +// @declaration: true +// @target: esnext +// @lib: esnext + +export const l = "A"; +export const l1 = l as typeof l; +export const l2 = l; +export let l3 = l as typeof l; +export let a4 = l; + +export const s = Symbol(); +export const s1 = s as typeof s; +export const s2 = s; +export let s3 = s as typeof s; +export let s4 = s; From 2cc17e82a25d67d654835392aad72f77e25c8955 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Thu, 5 Oct 2023 15:49:50 -0700 Subject: [PATCH 2/2] Don't widen unique symbol for different declarations --- src/compiler/checker.ts | 5 - tests/baselines/reference/issue55901.js | 8 +- tests/baselines/reference/issue55901.types | 8 +- tests/baselines/reference/uniqueSymbols.types | 64 ++--- .../uniqueSymbolsDeclarations.errors.txt | 247 ++++++++++++++++++ .../reference/uniqueSymbolsDeclarations.js | 135 ---------- .../reference/uniqueSymbolsDeclarations.types | 64 ++--- 7 files changed, 319 insertions(+), 212 deletions(-) create mode 100644 tests/baselines/reference/uniqueSymbolsDeclarations.errors.txt diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index ec5d1961f1a1c..f7df8e8b99646 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -11422,11 +11422,6 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { reportErrorsFromWidening(declaration, type); } - // always widen a 'unique symbol' type if the type was created for a different declaration. - if (type.flags & TypeFlags.UniqueESSymbol && (isBindingElement(declaration) || !declaration.type) && type.symbol !== getSymbolOfDeclaration(declaration)) { - type = esSymbolType; - } - return getWidenedType(type); } diff --git a/tests/baselines/reference/issue55901.js b/tests/baselines/reference/issue55901.js index 4eeffc30f46f9..11155529da990 100644 --- a/tests/baselines/reference/issue55901.js +++ b/tests/baselines/reference/issue55901.js @@ -34,7 +34,7 @@ export declare const l2 = "A"; export declare let l3: "A"; export declare let a4: string; export declare const s: unique symbol; -export declare const s1: symbol; -export declare const s2: symbol; -export declare let s3: symbol; -export declare let s4: symbol; +export declare const s1: typeof s; +export declare const s2: typeof s; +export declare let s3: typeof s; +export declare let s4: typeof s; diff --git a/tests/baselines/reference/issue55901.types b/tests/baselines/reference/issue55901.types index 11b3111bb7ee0..a9e57f4c7cb5f 100644 --- a/tests/baselines/reference/issue55901.types +++ b/tests/baselines/reference/issue55901.types @@ -31,22 +31,22 @@ export const s = Symbol(); >Symbol : SymbolConstructor export const s1 = s as typeof s; ->s1 : symbol +>s1 : unique symbol >s as typeof s : unique symbol >s : unique symbol >s : unique symbol export const s2 = s; ->s2 : symbol +>s2 : unique symbol >s : unique symbol export let s3 = s as typeof s; ->s3 : symbol +>s3 : unique symbol >s as typeof s : unique symbol >s : unique symbol >s : unique symbol export let s4 = s; ->s4 : symbol +>s4 : unique symbol >s : unique symbol diff --git a/tests/baselines/reference/uniqueSymbols.types b/tests/baselines/reference/uniqueSymbols.types index 37e1d29fcc38f..5850fc1e11b65 100644 --- a/tests/baselines/reference/uniqueSymbols.types +++ b/tests/baselines/reference/uniqueSymbols.types @@ -29,7 +29,7 @@ const constTypeAndCall: unique symbol = Symbol(); // declaration from initializer const constInitToConstCall = constCall; ->constInitToConstCall : symbol +>constInitToConstCall : unique symbol >constCall : unique symbol const constInitToLetCall = letCall; @@ -41,11 +41,11 @@ const constInitToVarCall = varCall; >varCall : symbol const constInitToConstDeclAmbient = constType; ->constInitToConstDeclAmbient : symbol +>constInitToConstDeclAmbient : unique symbol >constType : unique symbol let letInitToConstCall = constCall; ->letInitToConstCall : symbol +>letInitToConstCall : unique symbol >constCall : unique symbol let letInitToLetCall = letCall; @@ -57,11 +57,11 @@ let letInitToVarCall = varCall; >varCall : symbol let letInitToConstDeclAmbient = constType; ->letInitToConstDeclAmbient : symbol +>letInitToConstDeclAmbient : unique symbol >constType : unique symbol var varInitToConstCall = constCall; ->varInitToConstCall : symbol +>varInitToConstCall : unique symbol >constCall : unique symbol var varInitToLetCall = letCall; @@ -73,7 +73,7 @@ var varInitToVarCall = varCall; >varCall : symbol var varInitToConstDeclAmbient = constType; ->varInitToConstDeclAmbient : symbol +>varInitToConstDeclAmbient : unique symbol >constType : unique symbol // declaration from initializer with type query @@ -201,19 +201,19 @@ declare const c: C; >c : C const constInitToCReadonlyStaticCall = C.readonlyStaticCall; ->constInitToCReadonlyStaticCall : symbol +>constInitToCReadonlyStaticCall : unique symbol >C.readonlyStaticCall : unique symbol >C : typeof C >readonlyStaticCall : unique symbol const constInitToCReadonlyStaticType = C.readonlyStaticType; ->constInitToCReadonlyStaticType : symbol +>constInitToCReadonlyStaticType : unique symbol >C.readonlyStaticType : unique symbol >C : typeof C >readonlyStaticType : unique symbol const constInitToCReadonlyStaticTypeAndCall = C.readonlyStaticTypeAndCall; ->constInitToCReadonlyStaticTypeAndCall : symbol +>constInitToCReadonlyStaticTypeAndCall : unique symbol >C.readonlyStaticTypeAndCall : unique symbol >C : typeof C >readonlyStaticTypeAndCall : unique symbol @@ -311,7 +311,7 @@ declare const i: I; >i : I const constInitToIReadonlyType = i.readonlyType; ->constInitToIReadonlyType : symbol +>constInitToIReadonlyType : unique symbol >i.readonlyType : unique symbol >i : I >readonlyType : unique symbol @@ -349,13 +349,13 @@ declare const l: L; >l : L const constInitToLReadonlyType = l.readonlyType; ->constInitToLReadonlyType : symbol +>constInitToLReadonlyType : unique symbol >l.readonlyType : unique symbol >l : L >readonlyType : unique symbol const constInitToLReadonlyNestedType = l.nested.readonlyNestedType; ->constInitToLReadonlyNestedType : symbol +>constInitToLReadonlyNestedType : unique symbol >l.nested.readonlyNestedType : unique symbol >l.nested : { readonly readonlyNestedType: unique symbol; } >l : L @@ -486,8 +486,8 @@ f(N["s"]); // property assignments/methods const o2 = { ->o2 : { a: symbol; b: symbol; c: symbol; method1(): symbol; method2(): Promise; method3(): AsyncGenerator; method4(): Generator; method5(p?: symbol): symbol; } ->{ a: s, b: N.s, c: N["s"], method1() { return s; }, async method2() { return s; }, async * method3() { yield s; }, * method4() { yield s; }, method5(p = s) { return p; },} : { a: symbol; b: symbol; c: symbol; method1(): symbol; method2(): Promise; method3(): AsyncGenerator; method4(): Generator; method5(p?: symbol): symbol; } +>o2 : { a: symbol; b: symbol; c: symbol; method1(): symbol; method2(): Promise; method3(): AsyncGenerator; method4(): Generator; method5(p?: unique symbol): symbol; } +>{ a: s, b: N.s, c: N["s"], method1() { return s; }, async method2() { return s; }, async * method3() { yield s; }, * method4() { yield s; }, method5(p = s) { return p; },} : { a: symbol; b: symbol; c: symbol; method1(): symbol; method2(): Promise; method3(): AsyncGenerator; method4(): Generator; method5(p?: unique symbol): symbol; } a: s, >a : symbol @@ -524,10 +524,10 @@ const o2 = { >s : unique symbol method5(p = s) { return p; }, ->method5 : (p?: symbol) => symbol ->p : symbol +>method5 : (p?: unique symbol) => symbol +>p : unique symbol >s : unique symbol ->p : symbol +>p : unique symbol }; @@ -536,65 +536,65 @@ class C0 { >C0 : C0 static readonly a = s; ->a : symbol +>a : unique symbol >s : unique symbol static readonly b = N.s; ->b : symbol +>b : unique symbol >N.s : unique symbol >N : typeof N >s : unique symbol static readonly c = N["s"]; ->c : symbol +>c : unique symbol >N["s"] : unique symbol >N : typeof N >"s" : "s" static d = s; ->d : symbol +>d : unique symbol >s : unique symbol static e = N.s; ->e : symbol +>e : unique symbol >N.s : unique symbol >N : typeof N >s : unique symbol static f = N["s"]; ->f : symbol +>f : unique symbol >N["s"] : unique symbol >N : typeof N >"s" : "s" readonly a = s; ->a : symbol +>a : unique symbol >s : unique symbol readonly b = N.s; ->b : symbol +>b : unique symbol >N.s : unique symbol >N : typeof N >s : unique symbol readonly c = N["s"]; ->c : symbol +>c : unique symbol >N["s"] : unique symbol >N : typeof N >"s" : "s" d = s; ->d : symbol +>d : unique symbol >s : unique symbol e = N.s; ->e : symbol +>e : unique symbol >N.s : unique symbol >N : typeof N >s : unique symbol f = N["s"]; ->f : symbol +>f : unique symbol >N["s"] : unique symbol >N : typeof N >"s" : "s" @@ -618,10 +618,10 @@ class C0 { >s : unique symbol method5(p = s) { return p; } ->method5 : (p?: symbol) => symbol ->p : symbol +>method5 : (p?: unique symbol) => symbol +>p : unique symbol >s : unique symbol ->p : symbol +>p : unique symbol } // non-widening positions diff --git a/tests/baselines/reference/uniqueSymbolsDeclarations.errors.txt b/tests/baselines/reference/uniqueSymbolsDeclarations.errors.txt new file mode 100644 index 0000000000000..90fae715c43f6 --- /dev/null +++ b/tests/baselines/reference/uniqueSymbolsDeclarations.errors.txt @@ -0,0 +1,247 @@ +uniqueSymbolsDeclarations.ts(104,7): error TS2527: The inferred type of 'constInitToLReadonlyType' references an inaccessible 'unique symbol' type. A type annotation is necessary. +uniqueSymbolsDeclarations.ts(105,7): error TS2527: The inferred type of 'constInitToLReadonlyNestedType' references an inaccessible 'unique symbol' type. A type annotation is necessary. + + +==== uniqueSymbolsDeclarations.ts (2 errors) ==== + // declarations with call initializer + const constCall = Symbol(); + let letCall = Symbol(); + var varCall = Symbol(); + + // ambient declaration with type + declare const constType: unique symbol; + + // declaration with type and call initializer + const constTypeAndCall: unique symbol = Symbol(); + + // declaration from initializer + const constInitToConstCall = constCall; + const constInitToLetCall = letCall; + const constInitToVarCall = varCall; + const constInitToConstDeclAmbient = constType; + let letInitToConstCall = constCall; + let letInitToLetCall = letCall; + let letInitToVarCall = varCall; + let letInitToConstDeclAmbient = constType; + var varInitToConstCall = constCall; + var varInitToLetCall = letCall; + var varInitToVarCall = varCall; + var varInitToConstDeclAmbient = constType; + + // declaration from initializer with type query + const constInitToConstCallWithTypeQuery: typeof constCall = constCall; + const constInitToConstDeclAmbientWithTypeQuery: typeof constType = constType; + + // function return inference + function funcReturnConstCall() { return constCall; } + function funcReturnLetCall() { return letCall; } + function funcReturnVarCall() { return varCall; } + + // function return value with type query + function funcReturnConstCallWithTypeQuery(): typeof constCall { return constCall; } + + // generator function yield inference + function* genFuncYieldConstCall() { yield constCall; } + function* genFuncYieldLetCall() { yield letCall; } + function* genFuncYieldVarCall() { yield varCall; } + + // generator function yield with return type query + function* genFuncYieldConstCallWithTypeQuery(): IterableIterator { yield constCall; } + + // async function return inference + async function asyncFuncReturnConstCall() { return constCall; } + async function asyncFuncReturnLetCall() { return letCall; } + async function asyncFuncReturnVarCall() { return varCall; } + + // async generator function yield inference + async function* asyncGenFuncYieldConstCall() { yield constCall; } + async function* asyncGenFuncYieldLetCall() { yield letCall; } + async function* asyncGenFuncYieldVarCall() { yield varCall; } + + // classes + class C { + static readonly readonlyStaticCall = Symbol(); + static readonly readonlyStaticType: unique symbol; + static readonly readonlyStaticTypeAndCall: unique symbol = Symbol(); + static readwriteStaticCall = Symbol(); + + readonly readonlyCall = Symbol(); + readwriteCall = Symbol(); + } + declare const c: C; + + const constInitToCReadonlyStaticCall = C.readonlyStaticCall; + const constInitToCReadonlyStaticType = C.readonlyStaticType; + const constInitToCReadonlyStaticTypeAndCall = C.readonlyStaticTypeAndCall; + const constInitToCReadwriteStaticCall = C.readwriteStaticCall; + + const constInitToCReadonlyStaticCallWithTypeQuery: typeof C.readonlyStaticCall = C.readonlyStaticCall; + const constInitToCReadonlyStaticTypeWithTypeQuery: typeof C.readonlyStaticType = C.readonlyStaticType; + const constInitToCReadonlyStaticTypeAndCallWithTypeQuery: typeof C.readonlyStaticTypeAndCall = C.readonlyStaticTypeAndCall; + const constInitToCReadwriteStaticCallWithTypeQuery: typeof C.readwriteStaticCall = C.readwriteStaticCall; + + const constInitToCReadonlyCall = c.readonlyCall; + const constInitToCReadwriteCall = c.readwriteCall; + const constInitToCReadonlyCallWithTypeQuery: typeof c.readonlyCall = c.readonlyCall; + const constInitToCReadwriteCallWithTypeQuery: typeof c.readwriteCall = c.readwriteCall; + const constInitToCReadonlyCallWithIndexedAccess: C["readonlyCall"] = c.readonlyCall; + const constInitToCReadwriteCallWithIndexedAccess: C["readwriteCall"] = c.readwriteCall; + + // interfaces + interface I { + readonly readonlyType: unique symbol; + } + declare const i: I; + + const constInitToIReadonlyType = i.readonlyType; + const constInitToIReadonlyTypeWithTypeQuery: typeof i.readonlyType = i.readonlyType; + const constInitToIReadonlyTypeWithIndexedAccess: I["readonlyType"] = i.readonlyType; + + // type literals + type L = { + readonly readonlyType: unique symbol; + nested: { + readonly readonlyNestedType: unique symbol; + } + }; + declare const l: L; + + const constInitToLReadonlyType = l.readonlyType; + ~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2527: The inferred type of 'constInitToLReadonlyType' references an inaccessible 'unique symbol' type. A type annotation is necessary. + const constInitToLReadonlyNestedType = l.nested.readonlyNestedType; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2527: The inferred type of 'constInitToLReadonlyNestedType' references an inaccessible 'unique symbol' type. A type annotation is necessary. + const constInitToLReadonlyTypeWithTypeQuery: typeof l.readonlyType = l.readonlyType; + const constInitToLReadonlyNestedTypeWithTypeQuery: typeof l.nested.readonlyNestedType = l.nested.readonlyNestedType; + const constInitToLReadonlyTypeWithIndexedAccess: L["readonlyType"] = l.readonlyType; + const constInitToLReadonlyNestedTypeWithIndexedAccess: L["nested"]["readonlyNestedType"] = l.nested.readonlyNestedType; + + // type argument inference + const promiseForConstCall = Promise.resolve(constCall); + const arrayOfConstCall = [constCall]; + + // unique symbol widening in expressions + declare const s: unique symbol; + declare namespace N { const s: unique symbol; } + declare const o: { [s]: "a", [N.s]: "b" }; + declare function f(x: T): T; + declare function g(x: typeof s): void; + declare function g(x: typeof N.s): void; + + // widening positions + + // argument inference + f(s); + f(N.s); + f(N["s"]); + + // array literal elements + [s]; + [N.s]; + [N["s"]]; + + // property assignments/methods + const o2 = { + a: s, + b: N.s, + c: N["s"], + + method1() { return s; }, + async method2() { return s; }, + async * method3() { yield s; }, + * method4() { yield s; }, + method5(p = s) { return p; } + }; + + // property initializers + class C0 { + static readonly a = s; + static readonly b = N.s; + static readonly c = N["s"]; + + static d = s; + static e = N.s; + static f = N["s"]; + + readonly a = s; + readonly b = N.s; + readonly c = N["s"]; + + d = s; + e = N.s; + f = N["s"]; + + method1() { return s; } + async method2() { return s; } + async * method3() { yield s; } + * method4() { yield s; } + method5(p = s) { return p; } + } + + // non-widening positions + + // element access + o[s]; + o[N.s]; + o[N["s"]]; + + // arguments (no-inference) + f(s); + f(N.s); + f(N["s"]); + g(s); + g(N.s); + g(N["s"]); + + // falsy expressions + s || ""; + N.s || ""; + N["s"] || ""; + + // conditionals + Math.random() * 2 ? s : "a"; + Math.random() * 2 ? N.s : "a"; + Math.random() * 2 ? N["s"] : "a"; + + // computed property names + ({ + [s]: "a", + [N.s]: "b", + }); + + class C1 { + static [s]: "a"; + static [N.s]: "b"; + + [s]: "a"; + [N.s]: "b"; + } + + // contextual types + + interface Context { + method1(): typeof s; + method2(): Promise; + method3(): AsyncIterableIterator; + method4(): IterableIterator; + method5(p?: typeof s): typeof s; + } + + const o4: Context = { + method1() { + return s; // return type should not widen due to contextual type + }, + async method2() { + return s; // return type should not widen due to contextual type + }, + async * method3() { + yield s; // yield type should not widen due to contextual type + }, + * method4() { + yield s; // yield type should not widen due to contextual type + }, + method5(p = s) { // parameter should not widen due to contextual type + return p; + } + }; \ No newline at end of file diff --git a/tests/baselines/reference/uniqueSymbolsDeclarations.js b/tests/baselines/reference/uniqueSymbolsDeclarations.js index 01d07f1d9f1d5..bf0120fc106c8 100644 --- a/tests/baselines/reference/uniqueSymbolsDeclarations.js +++ b/tests/baselines/reference/uniqueSymbolsDeclarations.js @@ -406,138 +406,3 @@ const o4 = { return p; } }; - - -//// [uniqueSymbolsDeclarations.d.ts] -declare const constCall: unique symbol; -declare let letCall: symbol; -declare var varCall: symbol; -declare const constType: unique symbol; -declare const constTypeAndCall: unique symbol; -declare const constInitToConstCall: symbol; -declare const constInitToLetCall: symbol; -declare const constInitToVarCall: symbol; -declare const constInitToConstDeclAmbient: symbol; -declare let letInitToConstCall: symbol; -declare let letInitToLetCall: symbol; -declare let letInitToVarCall: symbol; -declare let letInitToConstDeclAmbient: symbol; -declare var varInitToConstCall: symbol; -declare var varInitToLetCall: symbol; -declare var varInitToVarCall: symbol; -declare var varInitToConstDeclAmbient: symbol; -declare const constInitToConstCallWithTypeQuery: typeof constCall; -declare const constInitToConstDeclAmbientWithTypeQuery: typeof constType; -declare function funcReturnConstCall(): symbol; -declare function funcReturnLetCall(): symbol; -declare function funcReturnVarCall(): symbol; -declare function funcReturnConstCallWithTypeQuery(): typeof constCall; -declare function genFuncYieldConstCall(): Generator; -declare function genFuncYieldLetCall(): Generator; -declare function genFuncYieldVarCall(): Generator; -declare function genFuncYieldConstCallWithTypeQuery(): IterableIterator; -declare function asyncFuncReturnConstCall(): Promise; -declare function asyncFuncReturnLetCall(): Promise; -declare function asyncFuncReturnVarCall(): Promise; -declare function asyncGenFuncYieldConstCall(): AsyncGenerator; -declare function asyncGenFuncYieldLetCall(): AsyncGenerator; -declare function asyncGenFuncYieldVarCall(): AsyncGenerator; -declare class C { - static readonly readonlyStaticCall: unique symbol; - static readonly readonlyStaticType: unique symbol; - static readonly readonlyStaticTypeAndCall: unique symbol; - static readwriteStaticCall: symbol; - readonly readonlyCall: symbol; - readwriteCall: symbol; -} -declare const c: C; -declare const constInitToCReadonlyStaticCall: symbol; -declare const constInitToCReadonlyStaticType: symbol; -declare const constInitToCReadonlyStaticTypeAndCall: symbol; -declare const constInitToCReadwriteStaticCall: symbol; -declare const constInitToCReadonlyStaticCallWithTypeQuery: typeof C.readonlyStaticCall; -declare const constInitToCReadonlyStaticTypeWithTypeQuery: typeof C.readonlyStaticType; -declare const constInitToCReadonlyStaticTypeAndCallWithTypeQuery: typeof C.readonlyStaticTypeAndCall; -declare const constInitToCReadwriteStaticCallWithTypeQuery: typeof C.readwriteStaticCall; -declare const constInitToCReadonlyCall: symbol; -declare const constInitToCReadwriteCall: symbol; -declare const constInitToCReadonlyCallWithTypeQuery: typeof c.readonlyCall; -declare const constInitToCReadwriteCallWithTypeQuery: typeof c.readwriteCall; -declare const constInitToCReadonlyCallWithIndexedAccess: C["readonlyCall"]; -declare const constInitToCReadwriteCallWithIndexedAccess: C["readwriteCall"]; -interface I { - readonly readonlyType: unique symbol; -} -declare const i: I; -declare const constInitToIReadonlyType: symbol; -declare const constInitToIReadonlyTypeWithTypeQuery: typeof i.readonlyType; -declare const constInitToIReadonlyTypeWithIndexedAccess: I["readonlyType"]; -type L = { - readonly readonlyType: unique symbol; - nested: { - readonly readonlyNestedType: unique symbol; - }; -}; -declare const l: L; -declare const constInitToLReadonlyType: symbol; -declare const constInitToLReadonlyNestedType: symbol; -declare const constInitToLReadonlyTypeWithTypeQuery: typeof l.readonlyType; -declare const constInitToLReadonlyNestedTypeWithTypeQuery: typeof l.nested.readonlyNestedType; -declare const constInitToLReadonlyTypeWithIndexedAccess: L["readonlyType"]; -declare const constInitToLReadonlyNestedTypeWithIndexedAccess: L["nested"]["readonlyNestedType"]; -declare const promiseForConstCall: Promise; -declare const arrayOfConstCall: symbol[]; -declare const s: unique symbol; -declare namespace N { - const s: unique symbol; -} -declare const o: { - [s]: "a"; - [N.s]: "b"; -}; -declare function f(x: T): T; -declare function g(x: typeof s): void; -declare function g(x: typeof N.s): void; -declare const o2: { - a: symbol; - b: symbol; - c: symbol; - method1(): symbol; - method2(): Promise; - method3(): AsyncGenerator; - method4(): Generator; - method5(p?: symbol): symbol; -}; -declare class C0 { - static readonly a: symbol; - static readonly b: symbol; - static readonly c: symbol; - static d: symbol; - static e: symbol; - static f: symbol; - readonly a: symbol; - readonly b: symbol; - readonly c: symbol; - d: symbol; - e: symbol; - f: symbol; - method1(): symbol; - method2(): Promise; - method3(): AsyncGenerator; - method4(): Generator; - method5(p?: symbol): symbol; -} -declare class C1 { - static [s]: "a"; - static [N.s]: "b"; - [s]: "a"; - [N.s]: "b"; -} -interface Context { - method1(): typeof s; - method2(): Promise; - method3(): AsyncIterableIterator; - method4(): IterableIterator; - method5(p?: typeof s): typeof s; -} -declare const o4: Context; diff --git a/tests/baselines/reference/uniqueSymbolsDeclarations.types b/tests/baselines/reference/uniqueSymbolsDeclarations.types index b22c81175916e..2cffd3a514efd 100644 --- a/tests/baselines/reference/uniqueSymbolsDeclarations.types +++ b/tests/baselines/reference/uniqueSymbolsDeclarations.types @@ -29,7 +29,7 @@ const constTypeAndCall: unique symbol = Symbol(); // declaration from initializer const constInitToConstCall = constCall; ->constInitToConstCall : symbol +>constInitToConstCall : unique symbol >constCall : unique symbol const constInitToLetCall = letCall; @@ -41,11 +41,11 @@ const constInitToVarCall = varCall; >varCall : symbol const constInitToConstDeclAmbient = constType; ->constInitToConstDeclAmbient : symbol +>constInitToConstDeclAmbient : unique symbol >constType : unique symbol let letInitToConstCall = constCall; ->letInitToConstCall : symbol +>letInitToConstCall : unique symbol >constCall : unique symbol let letInitToLetCall = letCall; @@ -57,11 +57,11 @@ let letInitToVarCall = varCall; >varCall : symbol let letInitToConstDeclAmbient = constType; ->letInitToConstDeclAmbient : symbol +>letInitToConstDeclAmbient : unique symbol >constType : unique symbol var varInitToConstCall = constCall; ->varInitToConstCall : symbol +>varInitToConstCall : unique symbol >constCall : unique symbol var varInitToLetCall = letCall; @@ -73,7 +73,7 @@ var varInitToVarCall = varCall; >varCall : symbol var varInitToConstDeclAmbient = constType; ->varInitToConstDeclAmbient : symbol +>varInitToConstDeclAmbient : unique symbol >constType : unique symbol // declaration from initializer with type query @@ -194,19 +194,19 @@ declare const c: C; >c : C const constInitToCReadonlyStaticCall = C.readonlyStaticCall; ->constInitToCReadonlyStaticCall : symbol +>constInitToCReadonlyStaticCall : unique symbol >C.readonlyStaticCall : unique symbol >C : typeof C >readonlyStaticCall : unique symbol const constInitToCReadonlyStaticType = C.readonlyStaticType; ->constInitToCReadonlyStaticType : symbol +>constInitToCReadonlyStaticType : unique symbol >C.readonlyStaticType : unique symbol >C : typeof C >readonlyStaticType : unique symbol const constInitToCReadonlyStaticTypeAndCall = C.readonlyStaticTypeAndCall; ->constInitToCReadonlyStaticTypeAndCall : symbol +>constInitToCReadonlyStaticTypeAndCall : unique symbol >C.readonlyStaticTypeAndCall : unique symbol >C : typeof C >readonlyStaticTypeAndCall : unique symbol @@ -304,7 +304,7 @@ declare const i: I; >i : I const constInitToIReadonlyType = i.readonlyType; ->constInitToIReadonlyType : symbol +>constInitToIReadonlyType : unique symbol >i.readonlyType : unique symbol >i : I >readonlyType : unique symbol @@ -342,13 +342,13 @@ declare const l: L; >l : L const constInitToLReadonlyType = l.readonlyType; ->constInitToLReadonlyType : symbol +>constInitToLReadonlyType : unique symbol >l.readonlyType : unique symbol >l : L >readonlyType : unique symbol const constInitToLReadonlyNestedType = l.nested.readonlyNestedType; ->constInitToLReadonlyNestedType : symbol +>constInitToLReadonlyNestedType : unique symbol >l.nested.readonlyNestedType : unique symbol >l.nested : { readonly readonlyNestedType: unique symbol; } >l : L @@ -479,8 +479,8 @@ f(N["s"]); // property assignments/methods const o2 = { ->o2 : { a: symbol; b: symbol; c: symbol; method1(): symbol; method2(): Promise; method3(): AsyncGenerator; method4(): Generator; method5(p?: symbol): symbol; } ->{ a: s, b: N.s, c: N["s"], method1() { return s; }, async method2() { return s; }, async * method3() { yield s; }, * method4() { yield s; }, method5(p = s) { return p; }} : { a: symbol; b: symbol; c: symbol; method1(): symbol; method2(): Promise; method3(): AsyncGenerator; method4(): Generator; method5(p?: symbol): symbol; } +>o2 : { a: symbol; b: symbol; c: symbol; method1(): symbol; method2(): Promise; method3(): AsyncGenerator; method4(): Generator; method5(p?: unique symbol): symbol; } +>{ a: s, b: N.s, c: N["s"], method1() { return s; }, async method2() { return s; }, async * method3() { yield s; }, * method4() { yield s; }, method5(p = s) { return p; }} : { a: symbol; b: symbol; c: symbol; method1(): symbol; method2(): Promise; method3(): AsyncGenerator; method4(): Generator; method5(p?: unique symbol): symbol; } a: s, >a : symbol @@ -517,10 +517,10 @@ const o2 = { >s : unique symbol method5(p = s) { return p; } ->method5 : (p?: symbol) => symbol ->p : symbol +>method5 : (p?: unique symbol) => symbol +>p : unique symbol >s : unique symbol ->p : symbol +>p : unique symbol }; @@ -529,65 +529,65 @@ class C0 { >C0 : C0 static readonly a = s; ->a : symbol +>a : unique symbol >s : unique symbol static readonly b = N.s; ->b : symbol +>b : unique symbol >N.s : unique symbol >N : typeof N >s : unique symbol static readonly c = N["s"]; ->c : symbol +>c : unique symbol >N["s"] : unique symbol >N : typeof N >"s" : "s" static d = s; ->d : symbol +>d : unique symbol >s : unique symbol static e = N.s; ->e : symbol +>e : unique symbol >N.s : unique symbol >N : typeof N >s : unique symbol static f = N["s"]; ->f : symbol +>f : unique symbol >N["s"] : unique symbol >N : typeof N >"s" : "s" readonly a = s; ->a : symbol +>a : unique symbol >s : unique symbol readonly b = N.s; ->b : symbol +>b : unique symbol >N.s : unique symbol >N : typeof N >s : unique symbol readonly c = N["s"]; ->c : symbol +>c : unique symbol >N["s"] : unique symbol >N : typeof N >"s" : "s" d = s; ->d : symbol +>d : unique symbol >s : unique symbol e = N.s; ->e : symbol +>e : unique symbol >N.s : unique symbol >N : typeof N >s : unique symbol f = N["s"]; ->f : symbol +>f : unique symbol >N["s"] : unique symbol >N : typeof N >"s" : "s" @@ -611,10 +611,10 @@ class C0 { >s : unique symbol method5(p = s) { return p; } ->method5 : (p?: symbol) => symbol ->p : symbol +>method5 : (p?: unique symbol) => symbol +>p : unique symbol >s : unique symbol ->p : symbol +>p : unique symbol } // non-widening positions