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

getType() for unique symbol returns typeof {nameOfVariable} rather than symbol #1453

Open
fuhrmanator opened this issue Sep 21, 2023 · 0 comments

Comments

@fuhrmanator
Copy link

Describe the bug

Version: 19.0.0

Variables declared with unique symbol type have a getType() value of typeof {nameOfVariable} rather than symbol

To Reproduce

Here's some code that reproduces the bug:

// test.ts
import { Project } from "ts-morph";

const code = `const aSymbol: symbol = Symbol("a");
const aUniqueSymbol: unique symbol = Symbol("b");
console.log(aSymbol, typeof aSymbol);
console.log(aUniqueSymbol, typeof aUniqueSymbol);
`;

const aSymbol: symbol = Symbol("a");
const aUniqueSymbol: unique symbol = Symbol("b");
console.log(aSymbol, typeof aSymbol);
console.log(aUniqueSymbol, typeof aUniqueSymbol);

const project = new Project();
project.createSourceFile("test_a.ts", code);

const aSymbolVariable = project.getSourceFile("test_a.ts")!.getVariableDeclarationOrThrow("aSymbol");
const aSymbolType = aSymbolVariable.getType();
console.log(`ts-morph: aSymbol's type: ${aSymbolType.getText()}`); // "symbol"

const aUniqueSymbolVariable = project.getSourceFile("test_a.ts")!.getVariableDeclarationOrThrow("aUniqueSymbol");
const aUniqueSymbolType = aUniqueSymbolVariable.getType();
console.log(`ts-morph: aUniqueSymbol's type: ${aUniqueSymbolType.getText()}`); // "symbol"

The output:

$ ts-node test.ts
Symbol(a) symbol
Symbol(b) symbol
ts-morph: aSymbol's type: symbol
ts-morph: aUniqueSymbol's type: typeof aUniqueSymbol

Expected behavior

I expected the type to be the same as the typeof result in TypeScript; that is, symbol.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant