microsoft / microsoft/TypeScript

namespace containing only 'const enum' can be used as value -> causing runtime error

Open
#28,590 0 comments 1 reaction 1 assignee View on GitHub

@weswigham is already working on this.

Since Dec 8, 2018.

Bug Domain: enum
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

TypeScript Version: 3.2.0-dev.20181110

Search Terms: namespace const enum

Code

namespace foo {
    export const enum Foo {}
}
console.log(foo);

Expected behavior:
Error when using foo as a value. It's already an error to use a namespace that contains only types (and is therefore not emitted) as value.
The Symbol of the ModuleDeclaration actually contains constEnumOnlyModule: true, it just needs to be checked.

Actual behavior:

Doesn't emit the namespace in transpiled output, but it's still referenced by console.log(foo);

Playground Link: https://agentcooper.github.io/typescript-play/#code/HYQwtgpgzgDiDGEAEAzA9mpBvAUE-SEAHjGgE4AuS8awUVEwArmEgGIbYC+OPNdaADYQAdILQBzABTo0ASgDcQA

Related Issues:

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.