常见。TypeScript 中的 NET-Class (即 List<T>)- 实现



如果你知道 TypeScript,你可能知道 DefinitelyTyped-Repository。我想知道是否有类似的东西,但是使用.ts文件.类网络功能?

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

正如我猜大多数打字稿用户都带有.NET-Background,我认为这是有道理的,我希望有人已经:)有同样的想法了?

干杯!

我有一个项目,它包含了一堆这些通用<T>数据结构:

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

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

例如一个集合:

/// <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] 

我在TypeScript中为C#程序员编写了一个泛型列表的示例实现(从InfoQ免费)。

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

import collections = require('fcl/collections');
var customers = new collections.List<Customer>();

最新更新