Include const enum members as possible literal types · Issue #7642 · microsoft/TypeScript (original) (raw)

Skip to content

Provide feedback

Saved searches

Use saved searches to filter your results more quickly

Sign up

@dead-claudia

Description

@dead-claudia

String literals are already valid types now. This is very nice, but I would like the ability to use const enum members to the same effect. They don't change, they take a lot less memory, and they're faster to check. Plus, you have a clearer distinction of what the type is, where strings are pretty free-form at times.

// Now type NodeType = "start" | "end"; // etc. interface Node { type: NodeType; }

interface StartNode { type: "start"; }

// What I'd like: const enum NodeType { Start, End, // etc. }

interface Node { type: NodeType; }

interface StartNode { type: NodeType.Start; }