Skip to content

Compiler API: A reference to an enum with one value references the enum value #46755

Open
@Gerrit0

Description

@Gerrit0

Bug Report

🔎 Search Terms

single member enum, reference types, compiler API

🕗 Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about symbol references

💻 Code

export enum CoolEnum {
//          ^^^^^^^^ symbol.id = 103
   FOO, 
// ^^^ symbol.id = 104
} 
 
export interface Response { 
    x:  CoolEnum 
//  ^ type.symbol.id = 104
}

If I add a second member to the enum, the symbol references change to work as expected.

export enum CoolEnum {
//          ^^^^^^^^ symbol.id = 103
    FOO,
//  ^^^ symbol.id = 104
    BAR,
//  ^^^ symbol.id = 105
} 
 
export interface Response { 
    x:  CoolEnum
//  ^ type.symbol.id = 103
}

🙁 Actual behavior

When enums have a single value, reference types which point to them have the type's symbol set to the only member of the enum, not to the enum's symbol.

🙂 Expected behavior

When enums have any number of values, reference types pointing to them should point to the enum itself.

Metadata

Metadata

Assignees

No one assigned

    Labels

    APIRelates to the public API for TypeScriptExperimentation NeededSomeone needs to try this out to see what happensSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions