通用.NET类(即List <t>) - TypeScript中的实现</t>

时间:2013-10-31 10:48:39

标签: .net github typescript

如果你知道TypeScript,你可能知道DefinitelyTyped-Repository。 我想知道是否有类似的东西,但是.ts-Files of .NET-Like-features?

所以例如,如果我喜欢.NET中的Queue-Class,我想知道是否有人在TypeScript中实现了一个实现,我可以在那里查找 - 或者如果我做了一个实现,我会知道在哪里存储它。

因为我猜大多数TypeScript用户都使用.NET-Background,我认为这样才有意义,我希望有人也认为相同:)?

干杯!

2 个答案:

答案 0 :(得分:5)

我有一个实现了许多通用<T>数据结构的项目:

- Linked List
- Dictionary
- Multi Dictionary
- Binary Search Tree
- Stack
- Queue
- Set
- Bag
- Binary Heap
- Priority Queue

来源:https://github.com/basarat/typescript-collections

E.g。一套:

/// <reference path="collections.ts" />
var x = new collections.Set<number>(); 
x.add(123);
x.add(123); // Duplicates not allowed in a set so will get filtered out
// The following will give error due to wrong type: 
// x.add("asdf"); // Can only add numbers since that is the type argument. 

var y = new collections.Set<number>();
y.add(456);
x.union(y);

console.log(x.toString()); // [123,456] 

答案 1 :(得分:2)

我在TypeScript for C# Programmers中编写了一个通用列表的示例实现(从InfoQ中解放出来)。

TypeScript没有自己的框架类库,因此除非有计划让TypeScript团队开始开发工作,否则社区需要创建一个。好消息是TypeScript具有所需的所有语言功能,并且使其模块化应该是微不足道的,因此您只需加载需要使用的FCL元素(使用模块加载器)。例如:

import collections = require('fcl/collections');

var customers = new collections.List<Customer>();