Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to use Typescript.Collections.HashTable in my code?

Tags:

typescript

I see in the code of the Typescript compiler, an implementation of "HashTable" (in the files src/compiler/core/hashTable.ts).

Do you know is there a way I can use it directly in my Typescript project ?

like image 788
Sébastien Renault Avatar asked Sep 11 '13 21:09

Sébastien Renault


1 Answers

You can implement a very simple hashtable where the key is a string by defining an interface

class Person {
    name: string;
}

interface HashTable<T> {
    [key: string]: T;
}

var persons: HashTable<Person> = {};
persons["bob"] = new Person();
var bob = persons["bob"];

It can only be keyed on a string or a number though.

like image 55
Ross Scott Avatar answered Oct 16 '22 04:10

Ross Scott