typescript object with string code example

Example 1: typescriprt specify type of key

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

Example 2: define object properties typescript

interface ISomeObject {
  subPropertie1: string,
  subPropertie2: number,
}

interface IProperties {
  property1: string,
  property2: boolean,
  property3: number[],
  property4: ISomeObject,
  property5: ISomeObject[],
}

function (args:IProperties): void {		// Sample Usage
  console.log(args.property1);
}