C# Dictionary in TypeScript? -


how should implement typescript interface define c# models:

public class pagemodel {     public long id { get; set; }     public string name { get; set; }     public idictionary<string, fieldmodel> fields { get; set; } }  public class fieldmodel {     public long id { get; set; }     public string name { get; set; }     public string type { get; set; }     public string datatype { get; set; }     public string defaultvalue { get; set; } } 

if you're looking interfaces then:

interface pagemodel {     id: number;     name: string;     fields: { [key: string]: fieldmodel }; }  interface fieldmodel {     id: number;     name: string;     type: string;     datatype: string;     defaultvalue: string; } 

some differences:

  1. javascript has no notion of long/integer/double, numbers
  2. in simple map implementation based on js object notation, keys strings. in typescript these called indexable types
  3. while use get/set inside classes, interfaces don't have , can define property.

Comments