getType() for `unique symbol` returns `typeof {nameOfVariable}` rather than `symbol`
- Dominant language
- TypeScript
- Stars
- 6.2k
- Forks
- 238
- Avg merge
- 2m
- Merged PRs (30d)
- 1
Description
**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:
```ts
// 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:
```terminal
$ 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`.
Contributor guide
Research direction
Start by reading CONTRIBUTING.md and running the TypeScript reproduction in test.ts, focusing on the getType() and getText() calls for the unique symbol declaration. Trace how ts-morph represents that type and add or update coverage for the reported case; done means the unique symbol variable reports symbol consistently with the expected output.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100