-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Labels
Working as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug
Description
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:
π 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.
jcalz
Metadata
Metadata
Assignees
Labels
Working as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug