{"id":7831,"date":"2015-10-31T01:24:50","date_gmt":"2015-10-31T01:24:50","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2015\/10\/31\/typescript-objects-as-dictionary-types-as-in-c-open-source-projects-microsoft-typescript\/"},"modified":"2015-10-31T01:24:50","modified_gmt":"2015-10-31T01:24:50","slug":"typescript-objects-as-dictionary-types-as-in-c-open-source-projects-microsoft-typescript","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2015\/10\/31\/typescript-objects-as-dictionary-types-as-in-c-open-source-projects-microsoft-typescript\/","title":{"rendered":"TypeScript Objects as Dictionary types as in C#-open source projects Microsoft\/TypeScript"},"content":{"rendered":"<p><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/6f45ffef27497554d8e3f6dbc52ed4da?s=128&amp;d=identicon&amp;r=PG\" \/> <strong>Ken Smith<\/strong><\/p>\n<p>You can do this in an array in JavaScript now, and so hence in TypeScript.<\/p>\n<pre><code>class User {\n    constructor(public name:string){}\n}\n\nvar users: User[] = [];\n\nusers['bob@gmail.com'] = new User('Bob');  \nalert(users['bob@gmail.com'].name);\n<\/code><\/pre>\n<p>TS doesn&#8217;t yet support Generics, so you can&#8217;t use anything besides a string or an integer as an index into the array, but using a string as an index is probably the most typical use for a dictionary anyway.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Ken Smith You can do this in an array in JavaScript now, and so hence in TypeScript. class User { constructor(public name:string){} } var users: User[] = []; users[&#8216;bob@gmail.com&#8217;] = new User(&#8216;Bob&#8217;); alert(users[&#8216;bob@gmail.com&#8217;].name); TS doesn&#8217;t yet support Generics, so you can&#8217;t use anything besides a string or an integer as an index into the array, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-7831","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/7831","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=7831"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/7831\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=7831"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=7831"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=7831"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}