Skip to content

enum values with indexOf or includes doesn't work properly. #40960

@ashr81

Description

@ashr81

TypeScript Version: 4.0.2

Search Terms:
indexOf or includes with enum

Code

enum TABLE_COLUMN {
    TEXT = 'TEXT'
}
type tableColumnType = keyof typeof TABLE_COLUMN;
const colType: tableColumnType = 'TEXT';
console.log(Object.values(TABLE_COLUMN).indexOf(colType)) //Argument of type '"TEXT"' is not assignable to parameter of type 'TABLE_COLUMN'.

Expected behavior:
Should correct take the union type and not throw any error.

Actual behavior:
Throws error when trying to find the value.

Playground Link: Link to playground here

Related Issues:

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions