-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptFixedA PR has been merged for this issueA PR has been merged for this issueGood First IssueWell scoped, documented and has the green lightWell scoped, documented and has the green lightHelp WantedYou can do thisYou can do this
Milestone
Description
TypeScript Version: 2.7.0-dev.20180105
Code index.ts
const enum FileType { png, jpg }
type FileTypeStr = keyof typeof FileType; // fails, not expected!
function f1(f: FileType) { }
function f2(f: FileTypeStr) { }
f1(FileType.png); // works as expected
f1(FileType.nope); // fails as expected
f2('png'); // works as expected
f2('nope'); // fails as expectedExpected behavior:
Expected the second line to work without compilation errors just like a non-const enum.
Actual behavior:
Emits an unexpected error on line 2:
index.ts(2,33): error TS2475: 'const' enums can only be used in property or index access expressions or the right hand side of an import declaration or export assignment.
Oddly enough, it looks like the type checking below the type declaration is working as expected. So I think this might be bug...line 2 should not be a compiler error.
Related issue: #14106
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptFixedA PR has been merged for this issueA PR has been merged for this issueGood First IssueWell scoped, documented and has the green lightWell scoped, documented and has the green lightHelp WantedYou can do thisYou can do this