var stuff: { [key: string]: string; } = {};
stuff['a'] = ''; // ok
stuff['a'] = 4; // error
// ... or, if you're using this a lot and don't want to type so much ...
interface StringMap { [key: string]: string; }
var stuff2: StringMap = { };
// same as above
More Related Contents:
- Is there a `valueof` similar to `keyof` in TypeScript?
- Generic type to get enum keys as union string in typescript?
- How do I dynamically assign properties to an object in TypeScript?
- Create a new object from type parameter in generic class
- Is it possible to restrict TypeScript object to contain only properties defined by its class?
- What is the Record type in typescript?
- Is there a way to check for both `null` and `undefined`?
- Extending component decorator with base class decorator
- Get properties of a class
- Select based on enum in Angular2
- ‘Cannot redeclare block-scoped variable’ in unrelated files
- typescript template literal as interface key
- How to undestand relations between types any, unknown, {} and between them and other types?
- Difference between extending and intersecting interfaces in TypeScript?
- How to do runtime type casting in TypeScript?
- How can moment.js be imported with typescript?
- Accessing properties in union types
- How can I remove a wider type from a union type without removing its subtypes in TypeScript?
- Generating typescript declaration files from javascript
- TypeScript empty object for a typed variable
- ts An async function or method in ES5/ES3 requires the ‘Promise’ constructor
- How to declare a function that throws an error in Typescript
- How to use enum as index key type in typescript?
- Typescript: change function type so that it returns new value
- What does a TypeScript index signature actually mean?
- Why does a Typescript type conditional on `T extends undefined`, with T instantiated with `boolean`, resolve T to `never`?
- What exactly $event object do in Angular 2?
- new Typescript “satisfies” operator
- What are the differences between the private keyword and private fields in TypeScript?
- Narrowing a return type from a generic, discriminated union in TypeScript