1

I have to translate C# app into TypeScript. It goes pretty well, but I have a problem with that:

private SharpKit.JavaScript.JsObject<JsString, JsBoolean> _changedLayers = new SharpKit.JavaScript.JsObject<JsString, JsBoolean>();

Does anyone know how to convert this?

[edit]
Ok, I guess I should do something like this:

private _changedLayers: (String, Boolean) => Object;

But now I wonder how to initialize this object? I tried this, but doesn't work...

this._changedLayers = { String: new String(), Boolean: new Boolean() };
Nickon
  • 9,652
  • 12
  • 64
  • 119

1 Answers1

4
var _changedLayers : { [key: string]: bool; } = {};

_changedLayers['foo'] = true; // ok
_changedLayers[1] = true; // error
_changedLayers['bar'] = 'abc'; // error

You could also define an interface:

interface StringToBoolMap {
    [key: string]: bool;
}

var _changedLayers : StringToBoolMap = {};
Markus Jarderot
  • 86,735
  • 21
  • 136
  • 138
  • Related: http://stackoverflow.com/questions/13631557/typescript-objects-as-dictionary-types-as-in-c-sharp/13631733#13631733 – Ryan Cavanaugh Dec 03 '12 at 18:31