microsoft / microsoft/TypeScript
namespace containing only 'const enum' can be used as value -> causing runtime error
@weswigham is already working on this.
Since Dec 8, 2018.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.