dsherret / dsherret/ts-morph

isEnum returns false when Enum property has a default value

Open
#1,491 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**

Version: 21.0.1

When a Class enum property has a default value of an enum member, `isEnum()` returns false as it sees the type from the enum value itself.

**To Reproduce**

```ts
import {Project} from "ts-morph";
const project = new Project();
project.createSourceFile("test.ts", `
export enum TestEnum {
A = 1,
}
export class TestClass {
p = TestEnum.A
}
`)

project.getSourceFiles().forEach(src => {
src.getClasses().forEach(cls => {
cls.getProperties().forEach(prop => {
console.log({
prop: prop.getName(),
type: prop.getType().getText(cls),
isEnum: prop.getType().isEnum(),
apparentType: prop.getType().getApparentType().getText(cls),
})
})
})
})

```

**Expected behavior**

would expect `property.getType().isEnum()` to return true

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.