In newer versions of typescript you can use:
type Customers = Record<string, Customer>
In older versions you can use:
var map: { [email: string]: Customer; } = { }; map['[email protected]'] = new Customer(); // OK map[14] = new Customer(); // Not OK, 14 is not a string map['[email protected]'] = 'x'; // Not OK, 'x' is not a customer
You can also make an interface if you don’t want to type that whole type annotation out every time:
interface StringToCustomerMap { [email: string]: Customer; } var map: StringToCustomerMap = { }; // Equivalent to first line of above
Related Posts:
- How do I remove an array item in TypeScript?
- type any? has no subscript members
- Create an empty object in JavaScript with {} or new Object()?
- Checking if a key exists in a JavaScript object?
- What’s the difference between “{}” and “[]” while declaring a JavaScript array?
- How to split a string into an array in Bash?
- How can I access and process nested objects, arrays or JSON?
- Converting array to list in Java
- What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it?
- Java Error “Exception in thread “main” java.util.InputMismatchException” On an Array program
- How to print elements in a vector c++
- Data type not understood while creating a NumPy array
- “Notice: Undefined variable”, “Notice: Undefined index”, and “Notice: Undefined offset” using PHP
- Are vectors passed to functions by value or by reference in C++
- How do I declare a 2d array in C++ using new?
- “error: assignment to expression with array type error” when I assign a struct field (C)
- Does JavaScript have a method like “range()” to generate a range within the supplied bounds?
- Getting “conflicting types for function” in C, why?
- Javascript Uncaught TypeError: Cannot read property ‘0’ of undefined
- Does JavaScript have a method like “range()” to generate a range within the supplied bounds?
- Form submission: PHP S_SESSION statements within a foreach loop
- How to split a string into an array in Bash?
- Working with a List of Lists in Java
- Array Size (Length) in C#
- Getting “conflicting types for function” in C, why?
- How to convert jsonString to JSONObject in Java
- Array of arrays (Python/NumPy)
- what does “>>>” mean in java?
- How to convert List
to int[] in Java? - Calculating Standard Deviation & Variance in C++
- Javascript Uncaught TypeError: Cannot read property ‘0’ of undefined
- How to convert int[] into List
in Java? - What is a list in Bash?
- What does ** do in C language?
- Correct way of looping through C++ arrays
- When will the worst case of Merge Sort occur?
- In Java, how to append a string more efficiently?
- How do I create an array of strings in C?
- What is the difference between ( for… in ) and ( for… of ) statements?
- Most efficient way to convert an HTMLCollection to an Array
- ow to create a histogram in java
- what does .space do in mips?
- What does << mean in Ruby?
- How can I create an array/list of dictionaries in python?
- Sort array of objects by object fields
- How to create an array of strings in C?
- Sorting arrays in javascript by object key value
- Initialization from incompatible pointer type warning when assigning to a pointer
- Convert Array to Object
- Bubble sort algorithm in MIPS
- How do I check whether an array contains a string in TypeScript?
- How to sort an array of objects in Java?
- How to sort an array of objects in Java?
- Error: unsupported use of matrix or array for column indexing
- push object into array
- Using multiple variables in a for loop in Python
- Weighted random selection from array
- Badly placed ()’s error with the following shell script
- Python dictionary from an object’s fields
- Error: Generic Array Creation
- Multidimensional Vectors in C++
- How to add an object to an array
- Java ArrayList for integers
- java.lang.ArrayIndexOutOfBoundsException: 4 Error
- IndexError: index 10 is out of bounds for axis 0 with size 10
- How to remove all duplicates from an array of objects?
- How to sort an array in Bash
- Sort array of objects by single key with date value
- Most efficient method to groupby on an array of objects
- How can I find the number of elements in an array?
- Array type char[] is not assignable
- Two-dimensional array in Swift
- Parameter name omitted error?
- C char array initialization
- How to iterate through table in Lua?
- How to sort in-place using the merge sort algorithm?
- Array of PHP Objects
- VBA array sort function?
- How to declare and use 1D and 2D byte arrays in Verilog?
- Difference between char *argv[] and char **argv for the second argument to main()
- Convert ArrayList
to java.util.List [closed] - Dynamic vs static array in c
- Complex JSON nesting of objects and arrays
- Array to Hash Ruby
- Print array elements on separate lines in Bash?
- Java says this method has a constructor name
- GCC: Array type has incomplete element type
- What is the best way to delete a value from an array in Perl?
- variably modified array at file scope in C
- Numpy matrix to array
- Using the Pythagorean theorem with Java
- How to iterate (keys, values) in JavaScript?
- Cast object to interface in TypeScript
- Sort an array in Java
- Remove properties from objects (JavaScript)
- How can I get list of values from dict?
- Warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11?
- Error when trying to inject a service into an angular component “EXCEPTION: Can’t resolve all parameters for component”, why?
- The difference between char * and char[] [duplicate]
- C# Dictionary get item by index