If you have string enum like so:

export enum LookingForEnum {
    Romantic = 'Romantic relationship',
    Casual = 'Casual relationship',
    Friends = 'Friends',
    Fun = 'Fun things to do!'
}

Then

 const index: number = Object.keys(LookingForEnum).indexOf('Casual'); // 1
Answer from Sampath on Stack Overflow
🌐
GitHub
github.com › microsoft › TypeScript › issues › 47231
Enum string index access/narrowing string to valid enum key · Issue #47231 · microsoft/TypeScript
November 8, 2021 - enum Test { ... } const key: string = '...'; if (key in Test) { // Error without this const value = Test[key]; } This would allow mapping of values that are potentially out of range/unsafe to an enum value.
Author   brunnerh
Discussions

String enum can't be used to index into an object
Property 'a' is missing in type '{ [x: string]: string | number | boolean; }'. src/test.ts(23,17): error TS7017: Element implicitly has an 'any' type because type 'Item' has no index signature. ... BugA bug in TypeScriptA bug in TypeScriptFixedA PR has been merged for this issueA PR has been ... More on github.com
🌐 github.com
6
June 27, 2017
How do I convert a string to enum in TypeScript? - Stack Overflow
It means that by default the TypeScript Enum type works with number indexes, i.e. let c = Color[0], but not with string indexes like let c = Color["string"]. This is a known restriction by the Microsoft team for the more general issue Object string indexes. More on stackoverflow.com
🌐 stackoverflow.com
dictionary - How to use enum as index key type in typescript? - Stack Overflow
So if you use an index signature you can index by any number or string (we can't restrict to only DialogType keys). The concept you are using here is called mapped types. Mapped types basically generate a new type based on a union of keys (in this case the members of DialogType enum) and a set ... More on stackoverflow.com
🌐 stackoverflow.com
Enum index signature to get enum value by string representation
As for now, in TS 1.9, enums has implicit index signature [index: number]: string, which could be used to get string representation of enum value, but there is no "reverse" index signatur... More on github.com
🌐 github.com
1
May 12, 2016
🌐
TypeScript
typescriptlang.org › docs › handbook › enums.html
TypeScript: Handbook - Enums
Enums allow a developer to define a set of named constants. Using enums can make it easier to document intent, or create a set of distinct cases. TypeScript provides both numeric and string-based enums.
🌐
GitHub
github.com › microsoft › TypeScript › issues › 16760
String enum can't be used to index into an object · Issue #16760 · microsoft/TypeScript
June 27, 2017 - enum Name { A = "a", B = "b", C = "c", } // interfaces with computed property names are not supported yet, see https://github.com/Microsoft/TypeScript/issues/5579 interface Item { /* [Name.A] */ a: string; /* [Name.B] */ b: number; /* [Name.C] */ c: boolean; } const names: Name[] = [Name.A, Name.B, Name.C]; const item: Item = { [Name.A]: "a", [Name.B]: 1, [Name.C]: true, }; names.forEach((name: Name) => { console.log(item[name]); });
Author   zakjan
🌐
Thoughtbot
thoughtbot.com › blog › the-trouble-with-typescript-enums
The trouble with TypeScript enums
January 10, 2025 - In the following TypeScript Playground example, the --strict flag (and therefore inherently the --noImplicitAny flag) is enabled, meaning this code will not compile: enum Fruits { Apple = 'APPLE', Pomegranate = 'POMEGRANATE', Persimmon = 'PERSIMMON' } const onFruitChanged = (value: string): void => { const fruit = Fruits[value]; console.log(fruit); } ... Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'typeof Fruits'.
🌐
Futurestud.io
futurestud.io › tutorials › typescript-using-a-string-as-enum-key
TypeScript — Using a String as Enum Key - Future Studio
February 1, 2024 - If you’re changing the type of key to a string, TypeScript fails because enums are not an index type and you can’t use a string value for indexed access:
🌐
DEV Community
dev.to › aumayeung › all-we-need-to-know-about-typescript-enums-329h
All We Need to Know About TypeScript Enums - DEV Community
May 1, 2020 - An enum type is a data type that has a set named values called elements, members, enumeral or enumerator of the type. They’re identifiers that act like constants in the language. In TypeScript, a numeric enum has a corresponding index ...
Find elsewhere
🌐
GitHub
github.com › Microsoft › TypeScript › issues › 9234
Enum index signature to get enum value by string representation · Issue #9234 · microsoft/TypeScript
May 12, 2016 - As for now, in TS 1.9, enums has implicit index signature [index: number]: string, which could be used to get string representation of enum value, but there is no "reverse" index signature: [index: string]: T where T is enum. enum Enum {...
Author   Strate
🌐
GitHub
github.com › microsoft › TypeScript › issues › 22892
Using string enum as key in {[key]: Type} throws not an index signature · Issue #22892 · microsoft/TypeScript
March 26, 2018 - TypeScript Version: 2.9.0-dev.20180325 Search Terms: string enum index signature cast Code enum Fruits { MANGO = 'MANGO', BANANA = 'BANANA', } type StringDict = { [key: string]: string }; function map(dict: StringDict, transform: (key: s...
Author   appsforartists
🌐
Webdevtutor
webdevtutor.net › blog › typescript-access-string-enum-by-index
How to Access String Enums by Index in TypeScript
April 11, 2021 - To access a string enum value by index, you can create a helper function that retrieves the value based on the index:
🌐
GitHub
github.com › microsoft › TypeScript › issues › 13042
Enums can not be used for index signature types · Issue #13042 · microsoft/TypeScript
June 13, 2016 - CommittedThe team has roadmapped ... idea for TypeScript ... export interface UserInterfaceColors { [index in UserInterfaceElement]: ColorInfo; } export interface ColorInfo { r: number; g: number; b: number; a: number; } export enum UserInterfaceElement { ActiveTitleBar = 0, InactiveTitleBar = 1, } Expected behavior: No errors will be thrown. Actual behavior: index in UserInterfaceElement throws the error Type 'UserInterfaceElement' is not assignable to type 'string...
Author   ChiriVulpes
🌐
LogRocket
blog.logrocket.com › home › how to iterate over enums in typescript (with code examples)
How to iterate over enums in TypeScript (with code examples) - LogRocket Blog
June 2, 2025 - "1 has index 0" "2 has index 1" "3 has index 2" "Green has index 3" "Yellow has index 4" "Red has index 5" See how the numeric keys appear first? This happens because numeric enums generate a reverse mapping — TypeScript compiles the enum to an object that contains both the forward mapping (key to value) and reverse mapping (value to key). The numeric keys “1”, “2”, “3” correspond to this reverse mapping. If we want to only list the string keys, we’ll have to filter out the numeric ones:
🌐
GitHub
github.com › microsoft › TypeScript › issues › 2491
Index signature parameter type should allow for enums · Issue #2491 · microsoft/TypeScript
January 17, 2015 - Enums are a convenient way of defining the domain of number and string value types, in cases such as · export interface UserInterfaceColors { [index: UserInterfaceElement]: ColorInfo; } export interface ColorInfo { r: number; g: number; b: ...
Author   jhlange
🌐
LogRocket
blog.logrocket.com › home › typescript string enums, and when and how to use them
TypeScript string enums, and when and how to use them - LogRocket Blog
August 13, 2024 - If you are new to the JavaScript/TypeScript landscape, you might be wondering what enums are. The enums keyword offers a way for us to define a finite set of values — usually as named constants in a strongly typed way.