diff --git a/types/collections/collections-tests.ts b/types/collections/collections-tests.ts new file mode 100644 index 0000000000..b7feef3c05 --- /dev/null +++ b/types/collections/collections-tests.ts @@ -0,0 +1,32 @@ +import SortedSet = require('collections/sorted-set'); + +interface Person { + name: string; +} + +let set = new SortedSet( + [{name: 'John'}, {name: 'Jack'}, {name: 'Linda'}], + (a: Person, b: Person) => a.name === b.name, + (a: Person, b: Person) => { + if (a.name < b.name) { + return -1; + } + if (a.name > b.name) { + return 1; + } + return 0; + } +); + +let p1: Person | undefined = set.max(); +let p2: Person | undefined = set.min(); + + +set.push({name: 'Laurie'}, {name: 'Max'}); +set.pop(); + +set.get({name: 'Laurie'}); +set.has({name: 'John'}); + +let a = 1; +set.forEach((p: Person) => a++); \ No newline at end of file diff --git a/types/collections/index.d.ts b/types/collections/index.d.ts new file mode 100644 index 0000000000..8a92df0f2d --- /dev/null +++ b/types/collections/index.d.ts @@ -0,0 +1,133 @@ +// Type definitions for collections v5.0.6 +// Project: http://www.collectionsjs.com/ +// Definitions by: Scarabe Dore +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +declare module 'collections/sorted-set' { + namespace internal { + // TODO: These methods can be similar in others collection. One's should make some + // class model. + abstract class AbstractSet { + union(...plus: any[]): any; + intersection(...plus: any[]): any; + difference(...plus: any[]): any; + symmetricDifference(...plus: any[]): any; + remove(...plus: any[]): any; + contains(...plus: any[]): any; + toggle(...plus: any[]): any; + addEach(...plus: any[]): any; + deleteEach(...plus: any[]): any; + deleteAll(...plus: any[]): any; + findValue(...plus: any[]): any; + iterator(...plus: any[]): any; + forEach(...plus: any[]): any; + map(...plus: any[]): any; + + filter(...plus: any[]): any; + group(...plus: any[]): any; + some(...plus: any[]): any; + every(...plus: any[]): any; + any(...plus: any[]): any; + all(...plus: any[]): any; + only(...plus: any[]): any; + sorted(...plus: any[]): any; + reversed(...plus: any[]): any; + join(...plus: any[]): any; + sum(...plus: any[]): any; + average(...plus: any[]): any; + zip(...plus: any[]): any; + enumerate(...plus: any[]): any; + concat(...plus: any[]): any; + flatten(...plus: any[]): any; + toArray(...plus: any[]): any; + toObject(...plus: any[]): any; + toJSON(...plus: any[]): any; + equals(...plus: any[]): any; + clone(...plus: any[]): any; + contentCompare(...plus: any[]): any; + contentEquals(...plus: any[]): any; + sortedSetLog(...plus: any[]): any; + addRangeChangeListener(...plus: any[]): any; + removeRangeChangeListener(...plus: any[]): any; + dispatchRangeChange(...plus: any[]): any; + addBeforeRangeChangeListener(...plus: any[]): any; + removeBeforeRangeChangeListener(...plus: any[]): any; + dispatchBeforeRangeChange(...plus: any[]): any; + addOwnPropertyChangeListener(...plus: any[]): any; + addBeforeOwnPropertyChangeListener(...plus: any[]): any; + removeOwnPropertyChangeListener(...plus: any[]): any; + removeBeforeOwnPropertyChangeListener(...plus: any[]): any; + dispatchOwnPropertyChange(...plus: any[]): any; + dispatchBeforeOwnPropertyChange(...plus: any[]): any; + makePropertyObservable(...plus: any[]): any; + } + + class Node { + reduce(cb: (result?: any, val?: any, key?: any, collection?: any) => any, + basis: any, index: number, thisp: any, tree: any, depth: number): any; + touch(...plus: any[]): void; + checkIntegrity(...plus: any[]): number; + getNext(...plus: any[]): Node | undefined; + getPrevious(...plus: any[]): Node | undefined; + summary(...plus: any[]): string; + log(charmap: any, logNode: any, log: any, logAbove: any): any; + } + + class Iterator { + next(): {done: true, value: T | null | undefined}; + } + + export class SortedSet extends AbstractSet { + constructor( + values?: T[], + equals?: (a: T, b: T) => boolean, + compare?: (a: T, b: T) => number, + getDefault?: any + ); + constructClone(values?: T[]): SortedSet; + + add(value: T): boolean; + clear(): void; + ['delete'](value: T): boolean; + + find(value: T): Node | undefined; + findGreatest(n?: Node | undefined): Node | undefined; + findGreatestLessThan(value: T): Node | undefined; + findGreatestLessThanOrEqual(value: T): Node | undefined; + findLeast(n?: Node | undefined): Node | undefined; + findLeastGreaterThan(value: T): Node | undefined; + findLeastGreaterThanOrEqual(value: T): Node | undefined; + max(n?: Node): T | undefined; + min(n?: Node): T | undefined; + one(): T | undefined; + + get(elt: T): T | undefined; + has(elt: T): boolean; + indexOf(value: T): number; + + pop(): T | undefined; + push(...rest: T[]): void; + + shift(): T | undefined; + unshift(...rest: T[]): void; + + slice(start?: number, end?: number): T[]; + splice(start: Node, length: number, ...values: T[]): T[]; + swap(start: number, length: number, values?: T[]): T[]; + + splay(value: T): void; + splayIndex(index: number): boolean; + + reduce(callback: (result?: any, val?: any, key?: any, collection?: any) => any, + basis?: any, thisp?: any): any; + reduceRight( + callback: (result?: any, val?: any, key?: any, collection?: any) => any, + basis?: any, thisp?: any + ): any; + + iterate(start: number, stop: number): Iterator; + } + } + + export = internal.SortedSet; +} diff --git a/types/collections/tsconfig.json b/types/collections/tsconfig.json new file mode 100644 index 0000000000..6b5293a242 --- /dev/null +++ b/types/collections/tsconfig.json @@ -0,0 +1,16 @@ +{ + "files": [ + "collections-tests.ts", + "index.d.ts" + ], + "compilerOptions": { + "module": "commonjs", + "target": "es6", + "lib": ["es6"], + "forceConsistentCasingInFileNames": true, + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "noEmit": true + } +} diff --git a/types/node-static/node-static-tests.ts b/types/node-static/node-static-tests.ts index 4bf2673ab4..471a8fde50 100644 --- a/types/node-static/node-static-tests.ts +++ b/types/node-static/node-static-tests.ts @@ -2,6 +2,6 @@ import {Server, version, mime} from 'node-static'; let server = new Server(__dirname); let pathname = server.resolve('./tsconfig.json'); -let mimetype = mime.lookup(pathname); +let mimetype = mime.lookup(pathname, ''); let versionNum = version.join('.'); console.log(`The node-static server constructed an instance of itself, fetched the mimetype of ${pathname} (${mimetype}), and has a version of ${versionNum}! The package is working.`); diff --git a/types/node/index.d.ts b/types/node/index.d.ts index 9c05e3ded9..d207554eda 100644 --- a/types/node/index.d.ts +++ b/types/node/index.d.ts @@ -2383,7 +2383,7 @@ declare module "net" { } export function createServer(connectionListener?: (socket: Socket) => void): Server; export function createServer(options?: { allowHalfOpen?: boolean, pauseOnConnect?: boolean }, connectionListener?: (socket: Socket) => void): Server; - export function connect(options: { port: number, host?: string, localAddress?: string, localPort?: string, family?: number, allowHalfOpen?: boolean; }, connectionListener?: Function): Socket; + export function connect(options: { port: number, host?: string, localAddress?: string, localPort?: number, family?: number, allowHalfOpen?: boolean; }, connectionListener?: Function): Socket; export function connect(port: number, host?: string, connectionListener?: Function): Socket; export function connect(path: string, connectionListener?: Function): Socket; export function createConnection(options: { port: number, host?: string, localAddress?: string, localPort?: string, family?: number, allowHalfOpen?: boolean; }, connectionListener?: Function): Socket;