dsherret / dsherret/ts-morph

ECMAScript symbol keys are not showing up in TypeLiteral.getType().getProperties()

Open
#1,365 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
6.2k
Forks
238
Avg merge
2m
Merged PRs (30d)
1

Description

**Describe the bug**

I'm able to pick up string and number keys of type literals just fine. But if I have a symbol key, it's invisible.

Version: 17.0.1

[ECMAScript symbols](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol) are not a well-known feature of the ECMAScript standard, but they have been around a while.

Test:
```ts
import { Project } from "ts-morph";

const project = new Project();
const sourceFile = project.createSourceFile("test.ts", `
const KeySymbol = Symbol("key");
type OneTwoKeyLiteral = {
one: false;
two: false;
[KeySymbol]: "key";
};
`);

// reproduce the problem here

const alias = sourceFile.getTypeAliasOrThrow("OneTwoKeyLiteral");
console.log(alias.getText()); // [KeySymbol] shows up as a property
console.log(alias.getType().getProperties().map(s => s.getName()); // ["foo", "bar"]
```

**Expected behavior**

The last line should log ` ["foo", "bar", "KeySymbol"].

The funny thing is, [ts-ast-viewer is inconsistent on this](
https://ts-ast-viewer.com/#code/MYewdgzgLgBA0gUwJ4GUkFsBGIA2MC8MaWuAFAEQDWy5AlANwBQUSADgjLIQN4zgIAuGADMAhjggIANJwDuIIVABOAV2kwA2olQZsOALowh5YSBDkYAXybM2HFQRjUkIYZyZA):

1. The TypeLiteral node has three members in the "Node" panel.
2. The TypeLiteral node has two members in the "Symbol" panel.
3. The TypeOfOperator node shows three types in the "Type" panel.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.