简体   繁体   English

TypeScript数据类型转换

[英]TypeScript Data Types casting

I am new in TypeScript/Angular JS 2. I have one function written in C# that I need to convert in TypeScript. 我是TypeScript / Angular JS 2的新手。我有一个用C#编写的函数,需要在TypeScript中进行转换。 Below is the function- 以下是功能-

public static MyModel GetDetails(IDictionary<string, object> Obj) {

  MyModel dlModel = new MyModel();
  if (Obj.ContainsKey("action"))

    dlModel.action = ((IEnumerable<object>)Obj["action"]).Cast<string>().ToList();
  if (Obj.ContainsKey("parameters")) {

    List<object> pr = ((IEnumerable<object>)Obj["parameters"]).Cast<object>().ToList();
    foreach (object obj in pr) {
      IDictionary<string, object> kValue = (IDictionary<string, object>)obj;

      dlModel.parameters.Add(new KeyValuePair<string, string>(kValue["Key"].ToString(), kValue["Value"].ToString()));


    }
}

But I am not sure how to use IDictionary and IEnumerable in TypeScript. 但是我不确定如何在TypeScript中使用IDictionary和IEnumerable。 So can anyone help me out in TypeScript data types. 任何人都可以在TypeScript数据类型中为我提供帮助。

So can anyone help me out in TypeScript data types. 任何人都可以在TypeScript数据类型中为我提供帮助。

Best to use {[key: string]: SomeObject} where SomeObject is the value for a given string key . 最好使用{[key: string]: SomeObject} ,其中SomeObject是给定字符串key

More 更多

Some docs on index signatures : https://basarat.gitbooks.io/typescript/content/docs/types/index-signatures.html 有关索引签名的一些文档: https : //basarat.gitbooks.io/typescript/content/docs/types/index-signatures.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM