Is there any way to use typescript in my code Collections. HashTable?

I saw the implementation of "hashtable" in the code of typescript compiler (in the file Src / compiler / core / hashtable. TS)

Do you know how to use it directly in my typescript project?

Solution

You can implement a very simple hash table by defining an interface, where the key is a string

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 type strings or numbers

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>