Skip to content

Using enum member with spaces in type position breaks TypeScriptΒ #43171

@AlCalzone

Description

@AlCalzone

Bug Report

πŸ”Ž Search Terms

enum type spaces

πŸ•— Version & Regression Information

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

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

enum Foo {
	Bar = 1,
	"B A Z" = 2,
}

interface CB {
	(arg1: Foo.Bar, arg2: string): void;
	(arg1: Foo["B A Z"], arg2: number): void;
	//         ^^^^^^^ error here, expected no error
}

declare const cb: CB;

cb(1, "1");
cb(1, 1); // expected error, got no error
cb(2, "2"); // expected error, got no error


// Workaround with `typeof`

interface CB2 {
	(arg1: Foo.Bar, arg2: string): void;
	(arg1: typeof Foo["B A Z"], arg2: number): void;
}

declare const cb2: CB2;

cb2(1, "1");
cb2(1, 1); // expected error, got no error
cb2(2, "2"); // expected error, got no error

πŸ™ Actual behavior

Enum value Foo["B A Z"] cannot be used in a type position. Working around it with typeof results in missing errors.

Bonus points in VSCode which generates invalid syntax on auto-completion:
ezgif com-video-to-gif(1)

πŸ™‚ Expected behavior

Foo["B A Z"] should be allowed in a type position like other enum members without spaces in the name. Typechecking should continue working.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions