Skip to content

Compiled object consisting of 2 enums does not compile to valid d.ts #40152

Closed

Description

@karpour

TypeScript Version: 3.9.7

Search Terms: quotations enum missing es2020

Code

The target in tsconfig for this code is ES2020

export enum SpotifyUnknownEnum { "unknown" = "u", "Unknown" = "u" }
export type SpotifyUnknown = keyof typeof SpotifyUnknownEnum;
enum AgeGroups { "0-17" , "18-22" , "23-27" , "28-34" , "35-44" , "45-59" , "60-150" }

export const SpotifyAgeGroupEnum = { ...AgeGroups, ...SpotifyUnknownEnum };

Expected behavior:

Valid JS Code

Actual behavior:

export declare enum SpotifyUnknownEnum {
    "unknown" = "u",
    "Unknown" = "u"
}
export declare type SpotifyUnknown = keyof typeof SpotifyUnknownEnum;
declare enum AgeGroups {
    "0-17" = 0,
    "18-22" = 1,
    "23-27" = 2,
    "28-34" = 3,
    "35-44" = 4,
    "45-59" = 5,
    "60-150" = 6
}
export declare const SpotifyAgeGroupEnum: {
    unknown: SpotifyUnknownEnum.unknown;
    Unknown: SpotifyUnknownEnum.unknown;
    "0-17": AgeGroups.0-17;
    "18-22": AgeGroups.18-22;
    "23-27": AgeGroups.23-27;
    "28-34": AgeGroups.28-34;
    "35-44": AgeGroups.35-44;
    "45-59": AgeGroups.45-59;
    "60-150": AgeGroups.60-150;
};
export {};

Obviously:

 "0-17": AgeGroups.0-17;

is not valid.

The problem is,

"0-17": AgeGroups["0-17"]; 

Is apparently also not valid in a d.ts file. So I can't even give a suggestion on how to compile this properly, since accessing an enum like this seems to be not possible in a d.ts file? Since it's valid TS code, it should compile to valid JS though.

Playground Link: https://www.typescriptlang.org/play?#code/KYDwDg9gTgLgBMAdgVwLZwMqRgSwGYCeAqogNaIQDuiAoiugN5wBEyZF1zcAvC8swBoWJclURderLgF8AUKEiw4MAmGCZs+YuzE84pYAQh5lq4MY0RchER1r0A3PPpwAggHNgAcSgRkYAGc4JmYABgBaAEYAdi4hZkiADnCAJhS4lhSAZlTYuHiU5KyAFgzmLIBWcOLS-JZiqoqATjKANgjIitCZWXlwaHgAYwhEAPgsKy0Pb19-OjQ9JgA6FemfP0ChFaWJ621Rann0aQcgA

Related Issues:

Activity

  1. j-oliveras commented on Aug 20, 2020

    @j-oliveras
    Contributor

    Simplified example:

    enum AgeGroups { "0-17" , "18-22" , "23-27" , "28-34" , "35-44" , "45-59" , "60-150" }
    export const SpotifyAgeGroupEnum = { ...AgeGroups };

    Playground

    Same errors on the generated d.ts

  2. added
    RescheduledThis issue was previously scheduled to an earlier milestone
    and removed
    RescheduledThis issue was previously scheduled to an earlier milestone
    on Aug 31, 2020
  3. locked as resolved and limited conversation to collaborators on Oct 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions