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

isEnum returns false when Enum property has a default value #1491

Open
d1rtym0nk3y opened this issue Jan 22, 2024 · 0 comments
Open

isEnum returns false when Enum property has a default value #1491

d1rtym0nk3y opened this issue Jan 22, 2024 · 0 comments

Comments

@d1rtym0nk3y
Copy link

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

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

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