Skip to content

const enum keyof typeof  #21031

Closed
Closed
@styfle

Description

@styfle

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 expected

Expected 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

No one assigned

    Labels

    BugA bug in TypeScriptFixedA PR has been merged for this issueGood First IssueWell scoped, documented and has the green lightHelp WantedYou can do this

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions