Skip to content

String literals not evaluate to string enum values. #22855

Closed
@electricessence

Description

@electricessence

TypeScript Version: 2.8.0

Search Terms:
string literal enum

Code

const enum TypeOfValue
{
	Boolean   = 'boolean',
	Number    = 'number',
	String    = 'string',
	Symbol    = 'symbol',
	Object    = 'object',
	Undefined = 'undefined',
	Function  = 'function'
}
if(typeof x==TypeOfValue.String) {
    // Type guard fails for string.
}

Expected behavior:
The code in the within the if block should understand that x is a string.

Actual behavior:
The if block is unaware of the type.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions