Skip to content

ES2015 Collections #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Aug 13, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ node_js:
- "stable"

script:
- npm run build+test
- npm run build
- npm run build-es6
- npm test
85 changes: 78 additions & 7 deletions 4/node.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,84 @@ interface ErrorConstructor {
stackTraceLimit(limit: number): void;
}

// compat for TypeScript 1.8
// if you use with --target es3 or --target es5 and use below definitions,
// use the lib.es6.d.ts that is bundled with TypeScript 1.8.
interface MapConstructor {}
interface WeakMapConstructor {}
interface SetConstructor {}
interface WeakSetConstructor {}
// ES2015 collection types
interface NodeCollection {
size: number;
}
interface NodeWeakCollection {
}
interface NodeCollectionConstructor<T> {
prototype: T;
}

interface Map<K, V> extends NodeCollection {
clear(): void;
delete(key: K): boolean;
entries(): Array<[K, V]>;
forEach(callbackfn: (value: V, index: K, map: Map<K, V>) => void, thisArg?: any): void;
get(key: K): V;
has(key: K): boolean;
keys(): Array<K>;
set(key: K, value?: V): Map<K, V>;
values(): Array<V>;
// [Symbol.iterator]():Array<[K,V]>;
// [Symbol.toStringTag]: "Map";
}

interface MapConstructor extends NodeCollectionConstructor<Map<any, any>> {
new (): Map<any, any>;
new <K, V>(): Map<K, V>;
}
declare var Map: MapConstructor;

interface WeakMap<K, V> extends NodeWeakCollection {
clear(): void;
delete(key: K): boolean;
get(key: K): V | void;
has(key: K): boolean;
set(key: K, value?: V): WeakMap<K, V>;
}

interface WeakMapConstructor extends NodeCollectionConstructor<WeakMap<any, any>> {
new (): WeakMap<any, any>;
new <K, V>(): WeakMap<K, V>;
}
declare var WeakMap: WeakMapConstructor;

interface Set<T> extends NodeCollection {
add(value: T): Set<T>;
clear(): void;
delete(value: T): boolean;
entries(): Array<[T, T]>;
forEach(callbackfn: (value: T, index: T, set: Set<T>) => void, thisArg?: any): void;
has(value: T): boolean;
keys(): Array<T>;
values(): Array<T>;
// [Symbol.iterator]():Array<T>;
// [Symbol.toStringTag]: "Set";
}

interface SetConstructor extends NodeCollectionConstructor<Set<any>> {
new (): Set<any>;
new <T>(): Set<T>;
new <T>(iterable: Array<T>): Set<T>;
}
declare var Set: SetConstructor;

interface WeakSet<T> extends NodeWeakCollection {
add(value: T): WeakSet<T>;
clear(): void;
delete(value: T): boolean;
has(value: T): boolean;
// [Symbol.toStringTag]: "WeakSet";
}

interface WeakSetConstructor extends NodeCollectionConstructor<WeakSet<any>> {
new (): WeakSet<any>;
new <T>(): WeakSet<T>;
new <T>(iterable: Array<T>): WeakSet<T>;
}
declare var WeakSet: WeakSetConstructor;

/************************************************
* *
Expand Down
85 changes: 78 additions & 7 deletions 6/node.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,84 @@ interface ErrorConstructor {
stackTraceLimit(limit: number): void;
}

// compat for TypeScript 1.8
// if you use with --target es3 or --target es5 and use below definitions,
// use the lib.es6.d.ts that is bundled with TypeScript 1.8.
interface MapConstructor { }
interface WeakMapConstructor { }
interface SetConstructor { }
interface WeakSetConstructor { }
// ES2015 collection types
interface NodeCollection {
size: number;
}
interface NodeWeakCollection {
}
interface NodeCollectionConstructor<T> {
prototype: T;
}

interface Map<K, V> extends NodeCollection {
clear(): void;
delete(key: K): boolean;
entries(): Array<[K, V]>;
forEach(callbackfn: (value: V, index: K, map: Map<K, V>) => void, thisArg?: any): void;
get(key: K): V;
has(key: K): boolean;
keys(): Array<K>;
set(key: K, value?: V): Map<K, V>;
values(): Array<V>;
// [Symbol.iterator]():Array<[K,V]>;
// [Symbol.toStringTag]: "Map";
}

interface MapConstructor extends NodeCollectionConstructor<Map<any, any>> {
new (): Map<any, any>;
new <K, V>(): Map<K, V>;
}
declare var Map: MapConstructor;

interface WeakMap<K, V> extends NodeWeakCollection {
clear(): void;
delete(key: K): boolean;
get(key: K): V | void;
has(key: K): boolean;
set(key: K, value?: V): WeakMap<K, V>;
}

interface WeakMapConstructor extends NodeCollectionConstructor<WeakMap<any, any>> {
new (): WeakMap<any, any>;
new <K, V>(): WeakMap<K, V>;
}
declare var WeakMap: WeakMapConstructor;

interface Set<T> extends NodeCollection {
add(value: T): Set<T>;
clear(): void;
delete(value: T): boolean;
entries(): Array<[T, T]>;
forEach(callbackfn: (value: T, index: T, set: Set<T>) => void, thisArg?: any): void;
has(value: T): boolean;
keys(): Array<T>;
values(): Array<T>;
// [Symbol.iterator]():Array<T>;
// [Symbol.toStringTag]: "Set";
}

interface SetConstructor extends NodeCollectionConstructor<Set<any>> {
new (): Set<any>;
new <T>(): Set<T>;
new <T>(iterable: Array<T>): Set<T>;
}
declare var Set: SetConstructor;

interface WeakSet<T> extends NodeWeakCollection {
add(value: T): WeakSet<T>;
clear(): void;
delete(value: T): boolean;
has(value: T): boolean;
// [Symbol.toStringTag]: "WeakSet";
}

interface WeakSetConstructor extends NodeCollectionConstructor<WeakSet<any>> {
new (): WeakSet<any>;
new <T>(): WeakSet<T>;
new <T>(iterable: Array<T>): WeakSet<T>;
}
declare var WeakSet: WeakSetConstructor;

/************************************************
* *
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"main": "index.js",
"scripts": {
"build": "tsc -p 0.8 && tsc -p 0.10 && tsc -p 0.11 && tsc -p 0.12 && tsc -p 4 && tsc -p 6",
"test": "tsc -p 0.11/test && tsc -p 0.12/test && tsc -p 4/test && tsc -p 6/test",
"build+test": "npm run build && npm test"
"build-es6": "tsc --target es6 -p 0.8 && tsc --target es6 -p 0.10 && tsc --target es6 -p 0.11 && tsc --target es6 -p 0.12 && tsc --target es6 -p 4 && tsc --target es6 -p 6",
"test": "tsc -p 0.11/test && tsc -p 0.12/test && tsc -p 4/test && tsc -p 6/test"
},
"repository": {
"type": "git",
Expand Down