Skip to content
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

Walk all outer expression kinds before comitting to the return type of a symbol call #61071

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
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
Next Next commit
Walk all outer expression kinds before comitting to the return type o…
…f a symbol call
Andarist committed Jan 29, 2025
commit 4e52cea0e57b3377fa346db89d089998ec3fe09f
2 changes: 1 addition & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
@@ -37245,7 +37245,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
// Treat any call to the global 'Symbol' function that is part of a const variable or readonly property
// as a fresh unique symbol literal type.
if (returnType.flags & TypeFlags.ESSymbolLike && isSymbolOrSymbolForCall(node)) {
return getESSymbolLikeTypeForNode(walkUpParenthesizedExpressions(node.parent));
return getESSymbolLikeTypeForNode(walkUpOuterExpressions(node));
}
if (
node.kind === SyntaxKind.CallExpression && !node.questionDotToken && node.parent.kind === SyntaxKind.ExpressionStatement &&
7 changes: 7 additions & 0 deletions tests/baselines/reference/uniqueSymbols.js
Original file line number Diff line number Diff line change
@@ -267,6 +267,10 @@ const ce0 = class {
function funcInferredReturnType(obj: { method(p: typeof s): void }) {
return obj;
}

// https://github.com/microsoft/TypeScript/issues/61070
const bar = Symbol('bar') satisfies symbol;
let bar2 = Symbol('bar2') satisfies symbol;


//// [uniqueSymbols.js]
@@ -458,3 +462,6 @@ const ce0 = class {
function funcInferredReturnType(obj) {
return obj;
}
// https://github.com/microsoft/TypeScript/issues/61070
const bar = Symbol('bar');
let bar2 = Symbol('bar2');
9 changes: 9 additions & 0 deletions tests/baselines/reference/uniqueSymbols.symbols
Original file line number Diff line number Diff line change
@@ -863,3 +863,12 @@ function funcInferredReturnType(obj: { method(p: typeof s): void }) {
>obj : Symbol(obj, Decl(uniqueSymbols.ts, 263, 32))
}

// https://github.com/microsoft/TypeScript/issues/61070
const bar = Symbol('bar') satisfies symbol;
>bar : Symbol(bar, Decl(uniqueSymbols.ts, 268, 5))
>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, --, --))

let bar2 = Symbol('bar2') satisfies symbol;
>bar2 : Symbol(bar2, Decl(uniqueSymbols.ts, 269, 3))
>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, --, --))

25 changes: 25 additions & 0 deletions tests/baselines/reference/uniqueSymbols.types
Original file line number Diff line number Diff line change
@@ -1443,3 +1443,28 @@ function funcInferredReturnType(obj: { method(p: typeof s): void }) {
> : ^^^^^^^^^ ^^ ^^^ ^^^
}

// https://github.com/microsoft/TypeScript/issues/61070
const bar = Symbol('bar') satisfies symbol;
>bar : unique symbol
> : ^^^^^^^^^^^^^
>Symbol('bar') satisfies symbol : unique symbol
> : ^^^^^^^^^^^^^
>Symbol('bar') : unique symbol
> : ^^^^^^^^^^^^^
>Symbol : SymbolConstructor
> : ^^^^^^^^^^^^^^^^^
>'bar' : "bar"
> : ^^^^^

let bar2 = Symbol('bar2') satisfies symbol;
>bar2 : symbol
> : ^^^^^^
>Symbol('bar2') satisfies symbol : symbol
> : ^^^^^^
>Symbol('bar2') : symbol
> : ^^^^^^
>Symbol : SymbolConstructor
> : ^^^^^^^^^^^^^^^^^
>'bar2' : "bar2"
> : ^^^^^^

4 changes: 4 additions & 0 deletions tests/cases/conformance/types/uniqueSymbol/uniqueSymbols.ts
Original file line number Diff line number Diff line change
@@ -269,3 +269,7 @@ const ce0 = class {
function funcInferredReturnType(obj: { method(p: typeof s): void }) {
return obj;
}

// https://github.com/microsoft/TypeScript/issues/61070
const bar = Symbol('bar') satisfies symbol;
let bar2 = Symbol('bar2') satisfies symbol;