basarat/typescript-collections sits at 1.2k stars on GitHub, written primarily in TypeScript. A generically typed set of collections for use with TypeScript
Snapshot summary built from the project's own GitHub metadata — there's no written TopGit review yet. The page will update automatically when a full review is published.
WHY NO REVIEW YET
TopGit writes full reviews for the most-starred, most-requested repositories. This page is a snapshot until then — see the READ ME tab for the original README in full.
var Collections = require('typescript-collections');
Visual Studio or other TypeScript IDE, will provide you with complete Intellisense (autocomplete) for your types.
The compiler will ensure that the collections contain the correct elements.
A sample Visual Studio project is in the demo folder.
Also available on NuGet : http://www.nuget.org/packages/typescript.collections/
Thanks to https://github.com/georgiosd
Example
import * as Collections from 'typescript-collections';
var mySet = new Collections.Set<number>();
mySet.add(123);
mySet.add(123); // Duplicates not allowed in a set
// The following will give error due to wrong type:
// mySet.add("asdf"); // Can only add numbers since that is the type argument.
var myQueue = new Collections.Queue();
myQueue.enqueue(1);
myQueue.enqueue(2);
console.log(myQueue.dequeue()); // prints 1
console.log(myQueue.dequeue()); // prints 2
Typings resolution
Remember to set "moduleResolution": "node", so TypeScript compiler can resolve typings in the node_modules/typescript-collections directory.
In browser usage
You should include umd.js or umd.min.js from dist/lib/ directory.
<script src="[server public path]/typescript-collections/dist/lib/umd.min.js"></script>
A note on Equality
Equality is important for hashing (e.g. dictionary / sets). Javascript only allows strings to be keys for the base dictionary {}.
This is why the implementation for these data structures uses the item's toString() method.
makeString utility function (aka. JSON.stringify)
A simple function is provided for you when you need a quick toString that uses all properties. E.g:
import * as Collections from 'typescript-collections';
class Car {
constructor(public company: string, public type: string, public year: number) {
}
toString() {
// Short hand. Adds each own property
return Collections.util.makeString(this);
}
}
console.log(new Car("BMW", "A", 2016).toString());
Output:
{company:BMW,type:A,year:2016}
A Sample on Dictionary
import * as Collections from 'typescript-collections';
class Person {
constructor(public name: string, public yearOfBirth: number,public city?:string) {
}
toString() {
return this.name + "-" + this.yearOfBirth; // City is not a part of the key.
}
}
class Car {
constructor(public company: string, public type: string, public year: number) {
}
toString() {
// Short hand. Adds each own property
return Collections.util.makeString(this);
}
}
var dict = new Collections.Dictionary<Person, Car>();
dict.setValue(new Person("john", 1970,"melbourne"), new Car("honda", "city", 2002));
dict.setValue(new Person("gavin", 1984), new Car("ferrari", "F50", 2006));
console.log("Orig");
console.log(dict);
// Changes the same john, since city is not part of key
dict.setValue(new Person("john", 1970, "sydney"), new Car("honda", "accord", 2006));
// Add a new john
dict.setValue(new Person("john", 1971), new Car("nissan", "micra", 2010));
console.log("Updated");
console.log(dict);
// Showing getting / setting a single car:
console.log("Single Item");
var person = new Person("john", 1970);
console.log("-Person:");
console.log(person);
var car = dict.getValue(person);
console.log("-Car:");
console.log(car.toString());
How active is development on basarat/typescript-collections?
The most recent commit recorded on basarat/typescript-collections was 3.6 years ago, based on the GitHub push timestamp. The repository has 153 forks — one of the better signals of community interest.
How many stars does basarat/typescript-collections have?
basarat/typescript-collections has 1.2k GitHub stars — refresh the page for the live number, or check github.com/basarat/typescript-collections. TopGit mirrors GitHub's count but does not claim minute-by-minute accuracy.
Is basarat/typescript-collections open source?
Yes — basarat/typescript-collections ships under the MIT license, which makes its source code freely readable (and, depending on license terms, forkable and reusable). Source: github.com/basarat/typescript-collections.
What is basarat/typescript-collections?
basarat/typescript-collections (basarat/typescript-collections) is a TypeScript project on GitHub. From the project's own README: A generically typed set of collections for use with TypeScript
Where do I read more about basarat/typescript-collections?
This TopGit page is a snapshot — the READ ME tab shows the project's own README content (links stripped, images preserved). The GitHub repository at github.com/basarat/typescript-collections is the definitive source.
Read full README in the tab above.
Is typescript-collections worth your time?
ChatGPT, Claude and Perplexity can all read this page. Ask one of them what it makes of typescript-collections.