From 9be408dd560e9358490be7276ed0a555d4b383d9 Mon Sep 17 00:00:00 2001 From: Cyril Schumacher Date: Mon, 9 Feb 2015 13:32:33 +0100 Subject: [PATCH 01/16] Remove module in IBAN definition. Add definition for "Java". --- iban/iban.d.ts | 90 ++++++++++++++++++------------------ java/java-tests.ts | 22 +++++++++ java/java-tests.ts.tscparams | 1 + java/java.d.ts | 52 +++++++++++++++++++++ 4 files changed, 119 insertions(+), 46 deletions(-) create mode 100644 java/java-tests.ts create mode 100644 java/java-tests.ts.tscparams create mode 100644 java/java.d.ts diff --git a/iban/iban.d.ts b/iban/iban.d.ts index b39f5908c..6a7bd803d 100644 --- a/iban/iban.d.ts +++ b/iban/iban.d.ts @@ -3,58 +3,56 @@ // Definitions by: Cyril Schumacher // Definitions: https://github.com/borisyankov/DefinitelyTyped -declare module ARHS { +/** + * @summary Interface for {@link IBAN} object. + * @author Cyril Schumacher + * @version 1.0 + */ +interface IBANStatic { /** - * @summary Interface for {@link IBAN} object. - * @author Cyril Schumacher - * @version 1.0 + * @summary Returns the IBAN in a electronic format. + * @param {string} iban The IBAN to convert. + * @param {string} The IBAN in electronic format. */ - interface IBANStatic { - /** - * @summary Returns the IBAN in a electronic format. - * @param {string} iban The IBAN to convert. - * @param {string} The IBAN in electronic format. - */ - electronicFormat(iban: string): string; + electronicFormat(iban: string): string; - /** - * @summary Convert the passed BBAN to an IBAN for this country specification. - * @param {string} countryCode The country of the BBAN. - * @param {string} bban The BBAN to convert to IBAN. - * @returns {string} The IBAN. - */ - fromBBAN(countryCode: string, bban: string): string; + /** + * @summary Convert the passed BBAN to an IBAN for this country specification. + * @param {string} countryCode The country of the BBAN. + * @param {string} bban The BBAN to convert to IBAN. + * @returns {string} The IBAN. + */ + fromBBAN(countryCode: string, bban: string): string; - /** - * @summary Check if the passed iban is valid according to this specification. - * @param {string} iban The iban to validate. - * @returns {boolean} True if valid, false otherwise. - */ - isValid(iban: string): boolean; + /** + * @summary Check if the passed iban is valid according to this specification. + * @param {string} iban The iban to validate. + * @returns {boolean} True if valid, false otherwise. + */ + isValid(iban: string): boolean; - /** - * @summary Check of the passed BBAN is valid. - * @param {string} countryCode The country of the BBAN. - * @param {string} bban The BBAN to validate. - * @returns {boolean} True if valid, false otherwise. - */ - isValidBBAN(countryCode: string, bban: string): boolean; + /** + * @summary Check of the passed BBAN is valid. + * @param {string} countryCode The country of the BBAN. + * @param {string} bban The BBAN to validate. + * @returns {boolean} True if valid, false otherwise. + */ + isValidBBAN(countryCode: string, bban: string): boolean; - /** - * @summary Returns the IBAN in a print format. - * @param {string} iban The IBAN to convert. - * @param {string} The IBAN in print format. - */ - printFormat(iban: string, separator: string[]): string; + /** + * @summary Returns the IBAN in a print format. + * @param {string} iban The IBAN to convert. + * @param {string} The IBAN in print format. + */ + printFormat(iban: string, separator: string[]): string; - /** - * @summary Convert the passed IBAN to a country-specific BBAN. - * @param {string} iban The IBAN to convert. - * @param {string[]} Separator the separator to use between BBAN blocks. - * @returns {string} The BBAN - */ - toBBAN(iban: string, separator: string[]): string; - } + /** + * @summary Convert the passed IBAN to a country-specific BBAN. + * @param {string} iban The IBAN to convert. + * @param {string[]} Separator the separator to use between BBAN blocks. + * @returns {string} The BBAN + */ + toBBAN(iban: string, separator: string[]): string; } -declare var IBAN: ARHS.IBANStatic; \ No newline at end of file +declare var IBAN: IBANStatic; \ No newline at end of file diff --git a/java/java-tests.ts b/java/java-tests.ts new file mode 100644 index 000000000..8bbbaea99 --- /dev/null +++ b/java/java-tests.ts @@ -0,0 +1,22 @@ +/// + +/** + * @summary Test for the applet status. + */ +function testStatus() { + var java: Java = { + status: AppletStatus.Loading + }; +} + +/** + * @summary Test for the handlers. + */ +function testHandlers() { + var handler: Function = () => {}; + var java: Java = { + onError: handler, + onLoad: handler, + onStop: handler + }; +} \ No newline at end of file diff --git a/java/java-tests.ts.tscparams b/java/java-tests.ts.tscparams new file mode 100644 index 000000000..934bc29ef --- /dev/null +++ b/java/java-tests.ts.tscparams @@ -0,0 +1 @@ +--noImplicitAny \ No newline at end of file diff --git a/java/java.d.ts b/java/java.d.ts new file mode 100644 index 000000000..a21a77228 --- /dev/null +++ b/java/java.d.ts @@ -0,0 +1,52 @@ +// Type definitions for Java +// Project: https://www.java.com/js/deployJava.txt +// Definitions by: Cyril Schumacher +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/** + * @summary Applet Status. + * {@link http://docs.oracle.com/javase/8/docs/technotes/guides/deploy/applet_dev_guide.html#JSDPG719|Applet Status And Event Handlers} + */ +declare enum AppletStatus { + /** + * @summary Applet is loading. + */ + Loading = 1, + + /** + * @summary Applet has loaded completely and is ready to receive JavaScript calls. + */ + Ready = 2, + + /** + * @summary Error while loading applet. + */ + Error = 3 +} + +/** + * @summary Interface for Java object. + * @author Cyril Schumacher + * @version 1.0 + */ +interface Java { + /** + * Handler if the applet status is ERROR. An error has occurred while loading the applet. + */ + onError?: Function; + + /** + * Handler if the applet status is READY. Applet has finished loading and is ready to receive JavaScript calls. + */ + onLoad?: Function; + + /** + * Handler if the applet has stopped. + */ + onStop?: Function; + + /** + * @summary Applet Status. + */ + status?: AppletStatus; +} \ No newline at end of file From 9cdfa999f555a64c1743f5b33abce73db8fe5a8e Mon Sep 17 00:00:00 2001 From: Cyril Schumacher Date: Mon, 9 Feb 2015 13:35:18 +0100 Subject: [PATCH 02/16] Update header. --- java/java.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/java/java.d.ts b/java/java.d.ts index a21a77228..44660aa32 100644 --- a/java/java.d.ts +++ b/java/java.d.ts @@ -1,5 +1,5 @@ // Type definitions for Java -// Project: https://www.java.com/js/deployJava.txt +// Project: https://www.java.com/ // Definitions by: Cyril Schumacher // Definitions: https://github.com/borisyankov/DefinitelyTyped From b63fcec22ae000d7d9f6240d832702b3be9566ea Mon Sep 17 00:00:00 2001 From: Cyril Schumacher Date: Mon, 9 Feb 2015 15:49:23 +0100 Subject: [PATCH 03/16] Rename the directory "java" to "java-applet". --- {java => java-applet}/java-tests.ts | 0 {java => java-applet}/java-tests.ts.tscparams | 0 {java => java-applet}/java.d.ts | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename {java => java-applet}/java-tests.ts (100%) rename {java => java-applet}/java-tests.ts.tscparams (100%) rename {java => java-applet}/java.d.ts (100%) diff --git a/java/java-tests.ts b/java-applet/java-tests.ts similarity index 100% rename from java/java-tests.ts rename to java-applet/java-tests.ts diff --git a/java/java-tests.ts.tscparams b/java-applet/java-tests.ts.tscparams similarity index 100% rename from java/java-tests.ts.tscparams rename to java-applet/java-tests.ts.tscparams diff --git a/java/java.d.ts b/java-applet/java.d.ts similarity index 100% rename from java/java.d.ts rename to java-applet/java.d.ts From 2c67795a50df65814ea7aa07d6f88684fc24e541 Mon Sep 17 00:00:00 2001 From: Cyril Schumacher Date: Mon, 9 Feb 2015 15:52:48 +0100 Subject: [PATCH 04/16] Rename files "java*.*" to "java-applet*.*". --- java-applet/{java-tests.ts => java-applet-tests.ts} | 4 ++-- ...java-tests.ts.tscparams => java-applet-tests.ts.tscparams} | 0 java-applet/{java.d.ts => java-applet.d.ts} | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename java-applet/{java-tests.ts => java-applet-tests.ts} (88%) rename java-applet/{java-tests.ts.tscparams => java-applet-tests.ts.tscparams} (100%) rename java-applet/{java.d.ts => java-applet.d.ts} (100%) diff --git a/java-applet/java-tests.ts b/java-applet/java-applet-tests.ts similarity index 88% rename from java-applet/java-tests.ts rename to java-applet/java-applet-tests.ts index 8bbbaea99..670527999 100644 --- a/java-applet/java-tests.ts +++ b/java-applet/java-applet-tests.ts @@ -1,4 +1,4 @@ -/// +/// /** * @summary Test for the applet status. @@ -19,4 +19,4 @@ function testHandlers() { onLoad: handler, onStop: handler }; -} \ No newline at end of file +} diff --git a/java-applet/java-tests.ts.tscparams b/java-applet/java-applet-tests.ts.tscparams similarity index 100% rename from java-applet/java-tests.ts.tscparams rename to java-applet/java-applet-tests.ts.tscparams diff --git a/java-applet/java.d.ts b/java-applet/java-applet.d.ts similarity index 100% rename from java-applet/java.d.ts rename to java-applet/java-applet.d.ts From 74b68be6cc87705072a819586d8bf6eb943a07ed Mon Sep 17 00:00:00 2001 From: Cyril Schumacher Date: Mon, 9 Feb 2015 15:55:03 +0100 Subject: [PATCH 05/16] Update header. --- java-applet/java-applet.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/java-applet/java-applet.d.ts b/java-applet/java-applet.d.ts index 44660aa32..0102b3b75 100644 --- a/java-applet/java-applet.d.ts +++ b/java-applet/java-applet.d.ts @@ -1,4 +1,4 @@ -// Type definitions for Java +// Type definitions for Java Applet // Project: https://www.java.com/ // Definitions by: Cyril Schumacher // Definitions: https://github.com/borisyankov/DefinitelyTyped @@ -49,4 +49,4 @@ interface Java { * @summary Applet Status. */ status?: AppletStatus; -} \ No newline at end of file +} From d2f90e7f2cfac02e4456f70b981d9d39ec3d057b Mon Sep 17 00:00:00 2001 From: Joel Wetzel Date: Mon, 9 Feb 2015 09:07:49 -0800 Subject: [PATCH 06/16] Update URI.d.ts uri.search(true) does return an object, but Typescript believes there is a difference between an Object and any. Thus, if your querystring includes ?myParam=myValue, you should be able to access the value using uri.search(true).myParam. However, the compiler threw the error "The property 'myParam' does not exist on on value of type 'Object'". Changing the return type to any fixes this. --- urijs/URI.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/urijs/URI.d.ts b/urijs/URI.d.ts index 21c7faf98..818c24a56 100644 --- a/urijs/URI.d.ts +++ b/urijs/URI.d.ts @@ -72,7 +72,7 @@ declare class URI { segment(level: string): string; search(): string; search(qry: string): URI; - search(qry: boolean): Object; + search(qry: boolean): any; search(qry: Object): URI; query(): string; query(qry: string): URI; From 188590dce9cf6c0ef105eb92ee5c404a0971fea0 Mon Sep 17 00:00:00 2001 From: Eric Lu Date: Mon, 9 Feb 2015 12:29:46 -0800 Subject: [PATCH 07/16] Expose isSecure function through request interface --- restify/restify.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/restify/restify.d.ts b/restify/restify.d.ts index 7128ca3d0..e890ef2b2 100644 --- a/restify/restify.d.ts +++ b/restify/restify.d.ts @@ -34,6 +34,7 @@ declare module "restify" { params: any; body?: any; //available when bodyParser plugin is used + isSecure: () => boolean; } interface Response extends http.ServerResponse { From 46916a7e8ebf5984f5e73dd140c51a2d27c41512 Mon Sep 17 00:00:00 2001 From: Jed Mao Date: Mon, 9 Feb 2015 21:43:53 -0600 Subject: [PATCH 08/16] Add tcomb definitions --- CONTRIBUTORS.md | 1 + tcomb/tcomb-tests.ts | 288 +++++++++++++++++++++++++++++ tcomb/tcomb.d.ts | 420 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 709 insertions(+) create mode 100644 tcomb/tcomb-tests.ts create mode 100644 tcomb/tcomb.d.ts diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index d4cc35d4e..f2ca4fe08 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -678,6 +678,7 @@ This document generated by [dt-contributors-generator](https://github.com/vvakam * [:link:](swiz/swiz.d.ts) [swiz](https://github.com/racker/node-swiz) by [Jeff Goddard](https://github.com/jedigo) * [:link:](tape/tape.d.ts) [tape](https://github.com/substack/tape) by [Bart van der Schoor](https://github.com/Bartvds) * [:link:](tar/tar.d.ts) [tar](https://github.com/npm/node-tar) by [Maxime LUCE](https://github.com/SomaticIT) +* [:link:](tcomb/tcomb.d.ts) [tcomb](https://github.com/npm/tcomb) by [Jed Mao](https://github.com/jedmao) * [:link:](tedious/tedious.d.ts) [tedious](https://pekim.github.io/tedious) by [Rogier Schouten](https://github.com/rogierschouten) * [:link:](tedious-connection-pool/tedious-connection-pool.d.ts) [tedious-connection-pool](https://github.com/pekim/tedious-connection-pool) by [Cyprien Autexier](https://github.com/sandorfr) * [:link:](teechart/teechart.d.ts) [TeeChart](http://www.steema.com) by [Steema Software](https://steema.com) diff --git a/tcomb/tcomb-tests.ts b/tcomb/tcomb-tests.ts new file mode 100644 index 000000000..aeecdcb31 --- /dev/null +++ b/tcomb/tcomb-tests.ts @@ -0,0 +1,288 @@ +// ReSharper disable InconsistentNaming +// ReSharper disable WrongExpressionStatement + +import t = require("tcomb"); + +var Str = t.Str; +var Num = t.Num; +var Bool = t.Bool; +var Arr = t.Arr; +var Obj = t.Obj; +var Func = t.Func; +var Err = t.Err; +var Re = t.Re; +var Dat = t.Dat; +var Nil = t.Nil; +var Any = t.Any; +var Type = t.Type; + +var struct = t.struct; +var tuple = t.tuple; +var list = t.list; +var dict = t.dict; +var union = t.union; +var maybe = t.maybe; +var func = t.func; +var subtype = t.subtype; + +Str.is("a string"); // => true +Str.is(1); // => false + +Num.is("a string"); // => true +Num.is(1); // => false + +Bool.is("a string"); // => true +Bool.is(1); // => false + +Arr.is("a string"); // => true +Arr.is(1); // => false + +Obj.is("a string"); // => true +Obj.is(1); // => false + +Func.is("a string"); // => true +Func.is(1); // => false + +Err.is("a string"); // => true +Err.is(1); // => false + +Re.is("a string"); // => true +Re.is(1); // => false + +Dat.is("a string"); // => true +Dat.is(1); // => false + +Nil.is("a string"); // => true +Nil.is(1); // => false + +Any.is("a string"); // => true +Any.is(1); // => false + +Type.is("a string"); // => true +Type.is(1); // => false + +var assert = t.assert; + +assert(t.Str.is("a string")); // => ok +assert(t.Str.is(1)); // => fail! + +var x = -2; +var min = 0; +// throws "-2 should be greater then 0" +assert(x > min, "%s should be greater then %s", x, min); + +Str("a string"); // => ok + +class Point1 { + x: number; + y: number; + constructor(x: number, y: number) { + this.x = Num(x); + this.y = Num(y); + } +} + +var Foo = t.irreducible("Foo", x => { + return t.Bool(x.hasOwnProperty("bar")); +}); + +Foo.is({ bar: "baz" }); // => true + +// defines a type representing positive numbers +var Positive = t.subtype(t.Num, n => { + return n >= 0; +}, "Positive"); + +Positive.is(1); // => true +Positive.is(-1); // => false + +var Country = t.enums({ + IT: "Italy", + US: "United States" +}, "Country"); + +Country.is("IT"); // => true +Country.is("FR"); // => false + +// values will mirror the keys +Country = t.enums.of("IT US", "Country"); + +// same as + +Country = t.enums(["IT", "US"], "Country"); + +// same as + +Country = t.enums({ + IT: "IT", + US: "US" +}, "Country"); + +var Point = t.struct({ + x: Num, + y: Num +}, "Point"); + +// constructor usage, `p` is immutable, new is optional +var p2 = new Point({ x: 1, y: 2 }); + +Point.is(p2); // => true + +// now p is mutable +new Point({ x: 1, y: 2 }, true); + +Point.extend({ z: Num }, "Point3D"); + +// multiple inheritance +var A = struct({}); +var B = struct({}); +var MixinC = {}; +var MixinD = {}; +A.extend([B, MixinC, MixinD]); + +var Rectangle = struct({ + width: Num, + height: Num +}); + +Rectangle.prototype.getArea = function() { + return this.width * this.height; +}; + +var Cube = Rectangle.extend({ + thickness: Num +}); + +// typeof Cube.prototype.getArea === 'function' +Cube.prototype.getVolume = function() { + return this.getArea() * this.thickness; +}; + +var Area = tuple([Num, Num]); + +// constructor usage, `area` is immutable +Area([1, 2]); + +var Path = list(Point); + +// costructor usage, `path` is immutable +Path([ + { x: 0, y: 0 }, // tcomb hydrates automatically using the `Point` constructor + { x: 1, y: 1 } +]); + +var Tel = dict(Str, Num); + +// costructor usage, `tel` is immutable +Tel({ jack: 4098, sape: 4139 }); + +var ReactKey = union([Str, Num]); + +ReactKey.is("a"); // => true +ReactKey.is(1); // => true +ReactKey.is(true); // => false + +ReactKey.dispatch = x => { + if (Str.is(x)) return Str; + if (Num.is(x)) return Num; + return Any; +}; + +// now you can do this without a fail +ReactKey("a"); + +// the value of a radio input where null = no selection +var Radio = maybe(Str); + +Radio.is("a"); // => true +Radio.is(null); // => true +Radio.is(1); // => false + +// add takes two `Num`s and returns a `Num` +var add = func([Num, Num], Num) + .of((x: number, y: number) => { return x + y; }); + +add("Hello", 2); // Raises error: Invalid `Hello` supplied to `Num` +add("Hello"); // Raises error: Invalid `Hello` supplied to `Num` + +add(1, 2); // Returns: 3 +add(1)(2); // Returns: 3 + +// An `A` takes a `Str` and returns an `Num` +func(Str, Num); + +// A `B` takes a `Func` (which takes a `Str` and returns a `Num`) and returns a `Str`. +func(func(Str, Num), Str); + +// An `ExcitedStr` is a `Str` containing an exclamation mark +var ExcitedStr = subtype(Str, s => { return s.indexOf("!") !== -1; }, "ExcitedStr"); + +// An `Exciter` takes a `Str` and returns an `ExcitedStr` +var Exciter = func(Str, ExcitedStr); + +// A `C` takes an `A`, a `B` and a `Str` and returns a `Num` +func([A, B, Str], Num); + +func(A, B).of(() => {}); + +var simpleQuestionator = Exciter.of((s: string) => { return s + "?"; }); +var simpleExciter = Exciter.of((s: string) => { return s + "!"; }); + +// Raises error: +// Invalid `Hello?` supplied to `ExcitedStr`, insert a valid value for the subtype +simpleQuestionator("Hello"); + +// Raises error: Invalid `1` supplied to `Str` +simpleExciter(1); + +// Returns: "Hello!" +simpleExciter("Hello"); + +// We can reasonably suggest that add has the following type signature +// add : Num -> Num -> Num +add = func([Num, Num], Num) + .of((x: number, y: number) => { return x + y }); + +add("Hello"); // As this raises: "Error: Invalid `Hello` supplied to `Num`" + +var add2 = add(2); +add2(1); // And this returns: 3 + +func(A, B).is(x); + +Exciter.is(simpleExciter); // Returns: true +Exciter.is(simpleQuestionator); // Returns: true + +var id = (x: number) => { return x; }; + +func([Num, Num], Num).is(func([Num, Num], Num).of(id)); // Returns: true +func([Num, Num], Num).is(func(Num, Num).of(id)); // Returns: false + +var p4 = new Point({x: 1, y: 2}); + +p4 = Point.update(p4, { x: { "$set": 3 } }); // => {x: 3, y: 2} + +var Type2 = dict(Str, Num); +var instance = Type2({ a: 1, b: 2 }); +Type2.update(instance, { $remove: ["a"] }); // => {b: 2} + +var Type3 = list(Num); +var instance2 = Type3([1, 2, 3, 4]); +Type3.update(instance2, { "$swap": { from: 1, to: 2 } }); // => [1, 3, 2, 4] + +t.options.onFail = message => { + return message; +}; + +t.format("Invalid argument `name` = `%s` supplied to `%s`", 1, "MyType"); + +t.getKind(Str); // => 'irreducible' +t.getKind(list(Str)); // => 'list' + +t.getFunctionName(t.getKind); // => 'getKind' +t.getFunctionName(() => { }); // => '' + +t.getTypeName(Str); + +t.mixin({ a: 1 }, { b: 2 }); // => {a: 1, b: 2} +t.mixin({ a: 1 }, { a: 2 }); // => fail! diff --git a/tcomb/tcomb.d.ts b/tcomb/tcomb.d.ts new file mode 100644 index 000000000..3c9197d86 --- /dev/null +++ b/tcomb/tcomb.d.ts @@ -0,0 +1,420 @@ +// Type definitions for tcomb v0.4 +// Project: http://gcanti.github.io/tcomb/guide/index.html +// Definitions by: Jed Mao +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +declare module tcomb { + + export var options: { + onFail: (message: string) => void; + }; + + /** + * Like util.format in Node. + */ + export function format(format: string, ...values: any[]): string; + export function getKind(type: T): string; + /** + * Returns a function's name or displayName if specified; otherwise, + * fallbacks on '>'. + */ + export function getFunctionName(fn: Function): string; + export function getTypeName(type: T): string; + /** + * Safe version of mixin, properties can be overwritten. + */ + export function mixin(target: {}, source: {}, overwrite?: boolean): any; + export var slice: typeof Array.prototype.slice; + export function shallowCopy(x: T): T; + export function update(instance: any, spec: {}): T; + /** + * If an assert fails the debugger kicks in so you can inspect the stack + * and quickly find out what's wrong. + * @param message - Useful for debugging. Formatted with values like util.format in Node. + * @param values - Sequentially inserted into the message. + */ + export function assert(condition: boolean, message?: string, ...values: any[]): void; + export function fail(message?: string): void; + + interface T { + meta: { + /** + * The type kind, equal to "irreducible" for irreducible types. + */ + kind: string; + /** + * The type name. + */ + name: string; + }; + displayName: string; + is(value: any): boolean; + update(instance: any, spec: {}): T; + } + + interface TypePredicate { + (x: any): Bool_Instance; + } + + interface Any_Instance { + } + + interface Any_Static extends T { + new (value: any): Any_Instance; + (value: any): Any_Instance; + } + + export var Any: Any_Static; + + interface Nil_Instance { + } + + interface Nil_Static extends T { + new (value: any): Nil_Instance; + (value: any): Nil_Instance; + } + + export var Nil: Str_Static; + + interface Str_Instance extends String { + } + + interface Str_Static extends T { + new (value: string): Str_Instance; + (value: string): Str_Instance; + meta: { + /** + * The type kind, equal to "irreducible" for irreducible types. + */ + kind: string; + /** + * The type name. + */ + name: string; + /** + * The type predicate. + */ + is: TypePredicate; + }; + } + + export var Str: Str_Static; + + interface Num_Instance extends Number { + } + + interface Num_Static extends T { + new (value: number): Num_Instance; + (value: number): Num_Instance; + } + + export var Num: Num_Static; + + interface Bool_Instance extends Boolean { + } + + interface Bool_Static extends T { + new (value: boolean): Bool_Instance; + (value: boolean): Bool_Instance; + } + + export var Bool: Bool_Static; + + interface Arr_Instance extends Array { + } + + interface Arr_Static extends T { + new (value: any[]): Arr_Instance; + (value: any[]): Arr_Instance; + } + + export var Arr: Arr_Static; + + interface Obj_Instance extends Object { + } + + interface Obj_Static extends T { + new (value: Object): Obj_Instance; + (value: Object): Obj_Instance; + } + + export var Obj: Obj_Static; + + interface Func_Instance extends Function { + } + + interface Func_Static extends T { + new (value: Function): Func_Instance; + (value: Function): Func_Instance; + } + + export var Func: Func_Static; + + interface Err_Instance extends Error { + } + + interface Err_Static extends T { + new (value: Error): Err_Instance; + (value: Error): Err_Instance; + } + + export var Err: Err_Static; + + interface Re_Instance extends RegExp { + } + + interface Re_Static extends T { + new (value: RegExp): Re_Instance; + (value: RegExp): Re_Instance; + } + + export var Re: Re_Static; + + interface Dat_Instance extends Date { + } + + interface Dat_Static extends T { + new (value: Date): Dat_Instance; + (value: Date): Dat_Instance; + } + + export var Dat: Dat_Static; + + interface Type_Instance { + } + + interface Type_Static extends T { + new (value: any): Type_Instance; + (value: any): Type_Instance; + } + + export var Type: Type_Static; + + /** + * @param name - The type name. + * @param is - A predicate. + */ + export function irreducible(name: string, is: TypePredicate): T; + /** + * @param props - A hash whose keys are the field names and the values are the fields types. + * @param name - Useful for debugging purposes. + */ + export function struct(props: Object, name?: string): typeof Struct; + + export interface Struct_Static extends T { + new (value: any, mutable?: boolean): Struct_Instance; + (value: any, mutable?: boolean): Struct_Instance; + meta: { + kind: string; + name: string; + props: any[]; + }; + /** + * @param mixins - Contains the new props. + * @param name - Useful for debugging purposes. + */ + extend(mixins: Object, name?: string): Struct_Static; + /** + * @param mixins - Contains the new props. + * @param name - Useful for debugging purposes. + */ + extend(mixins: Struct_Static, name?: string): Struct_Static; + /** + * @param mixins - Contains the new props. + * @param name - Useful for debugging purposes. + */ + extend(mixins: Object[], name?: string): Struct_Static; + /** + * @param mixins - Contains the new props. + * @param name - Useful for debugging purposes. + */ + extend(mixins: Struct_Static[], name?: string): Struct_Static; + } + + interface Struct_Instance { + } + + export var Struct: Struct_Static; + + /** + * @param map - A hash whose keys are the enums (values are free). + * @param name - Useful for debugging purposes. + */ + export function enums(map: Object, name?: string): T; + export module enums { + /** + * @param keys - Array of enums. + * @param name - Useful for debugging purposes. + */ + export function of(keys: string[], name?: string): T; + /** + * @param keys - String of enums separated by spaces. + * @param name - Useful for debugging purposes. + */ + export function of(keys: string, name?: string): T; + } + + /** + * @param name - Useful for debugging purposes. + */ + export function union(types: T[], name?: string): Union_Static; + + interface Union_Static extends T { + new (value: any, mutable?: boolean): Union_Instance; + (value: any, mutable?: boolean): Union_Instance; + meta: { + kind: string; + name: string; + types: T[]; + }; + dispatch(x: any): T; + } + + interface Union_Instance { + } + + export var Union: Union_Static; + + /** + * @param type - The wrapped type. + * @param name - Useful for debugging purposes. + */ + export function maybe(type: T, name?: string): Maybe_Static; + + export interface Maybe_Static extends T { + new (value: any, mutable?: boolean): Maybe_Instance; + (value: any, mutable?: boolean): Maybe_Instance; + meta: { + kind: string; + name: string; + typee: T; + }; + } + + interface Maybe_Instance { + } + + export var Maybe: Maybe_Static; + + /** + * @param name - Useful for debugging purposes. + */ + export function tuple(types: T[], name?: string): Tuple_Static; + + interface Tuple_Static extends T { + new (value: any, mutable?: boolean): Tuple_Instance; + (value: any, mutable?: boolean): Tuple_Instance; + meta: { + kind: string; + name: string; + types: T[]; + }; + } + + interface Tuple_Instance { + } + + export var Tuple: Tuple_Static; + + /** + * Combines old types into a new one. + * @param type - A type already defined. + * @param name - Useful for debugging purposes. + */ + export function subtype(type: T, predicate: TypePredicate, name?: string): typeof Subtype; + + interface Subtype_Static extends T { + new (value: any, mutable?: boolean): Subtype_Instance; + (value: any, mutable?: boolean): Subtype_Instance; + meta: { + kind: string; + name: string; + type: T; + predicate: TypePredicate; + }; + } + + interface Subtype_Instance { + } + + export var Subtype: Subtype_Static; + + /** + * @param type - The type of list items. + * @param name - Useful for debugging purposes. + */ + export function list(type: T, name?: string): List_Static; + + interface List_Static extends T { + new (value: any, mutable?: boolean): List_Instance; + (value: any, mutable?: boolean): List_Instance; + meta: { + kind: string; + name: string; + 'type': T; + }; + } + + interface List_Instance { + } + + export var List: List_Static; + + /** + * @param domain - The type of keys. + * @param codomain - The type of values. + * @param name - Useful for debugging purposes. + */ + export function dict(domain: T, codomain: T, name?: string): Dict_Static; + + interface Dict_Static extends T { + new (value: any, mutable?: boolean): Dict_Instance; + (value: any, mutable?: boolean): Dict_Instance; + meta: { + kind: string; + name: string; + domain: T; + codomain: T; + }; + } + + interface Dict_Instance { + } + + export var Dict: Dict_Static; + + /** + * @param type - The type of the function's argument. + * @param codomain - The type of the function's return value. + * @param name - Useful for debugging purposes. + */ + export function func(domain: T, codomain: T, name?: string): Func_Static; + /** + * @param type - The list of types of the function's arguments. + * @param codomain - The type of the function's return value. + * @param name - Useful for debugging purposes. + */ + export function func(domain: T[], codomain: T, name?: string): Func_Static; + + interface Func_Static extends T { + new (value: any, mutable?: boolean): Func_Instance; + (value: any, mutable?: boolean): Func_Instance; + meta: { + kind: string; + name: string; + domain: any; + codomain: T; + }; + of(fn: Function): Function; + } + + interface Func_Instance { + } + + export var Func: Func_Static; + +} + +declare module "tcomb" { + export = tcomb; +} From 01d3cc0458f2c17a4e574e457ae514c6c0c7510f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jukka=20Hyv=C3=A4rinen?= Date: Tue, 10 Feb 2015 12:52:51 +0200 Subject: [PATCH 09/16] Added IRepeatScope --- angularjs/angular.d.ts | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/angularjs/angular.d.ts b/angularjs/angular.d.ts index f9ebda120..5dd540aaf 100755 --- a/angularjs/angular.d.ts +++ b/angularjs/angular.d.ts @@ -584,6 +584,44 @@ declare module ng { } interface IScope extends IRootScopeService { } + + /** + * $scope for ngRepeat directive. + * see https://docs.angularjs.org/api/ng/directive/ngRepeat + */ + interface IRepeatScope extends IScope { + + /** + * iterator offset of the repeated element (0..length-1). + */ + $index: number; + + /** + * true if the repeated element is first in the iterator. + */ + $first: boolean; + + /** + * true if the repeated element is between the first and last in the iterator. + */ + $middle: boolean; + + /** + * true if the repeated element is last in the iterator. + */ + $last: boolean; + + /** + * true if the iterator position $index is even (otherwise false). + */ + $even: boolean; + + /** + * true if the iterator position $index is odd (otherwise false). + */ + $odd: boolean; + + } interface IAngularEvent { /** From 8c30472a68695c87fe941a7c28efb80a2e121923 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jukka=20Hyv=C3=A4rinen?= Date: Tue, 10 Feb 2015 14:06:32 +0200 Subject: [PATCH 10/16] indentation --- angularjs/angular.d.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/angularjs/angular.d.ts b/angularjs/angular.d.ts index 5dd540aaf..d764bec6b 100755 --- a/angularjs/angular.d.ts +++ b/angularjs/angular.d.ts @@ -589,37 +589,37 @@ declare module ng { * $scope for ngRepeat directive. * see https://docs.angularjs.org/api/ng/directive/ngRepeat */ - interface IRepeatScope extends IScope { + interface IRepeatScope extends IScope { /** * iterator offset of the repeated element (0..length-1). */ - $index: number; + $index: number; /** * true if the repeated element is first in the iterator. */ - $first: boolean; + $first: boolean; /** * true if the repeated element is between the first and last in the iterator. */ - $middle: boolean; + $middle: boolean; /** * true if the repeated element is last in the iterator. */ - $last: boolean; + $last: boolean; /** * true if the iterator position $index is even (otherwise false). */ - $even: boolean; + $even: boolean; /** * true if the iterator position $index is odd (otherwise false). */ - $odd: boolean; + $odd: boolean; } From 1b8c6b6cf475f9f579e6e989ee5409b2f2ca8bc0 Mon Sep 17 00:00:00 2001 From: Panu Horsmalahti Date: Tue, 10 Feb 2015 15:55:31 +0200 Subject: [PATCH 11/16] Add MongoDB stats type --- mongodb/mongodb-tests.ts | 7 ++++++- mongodb/mongodb.d.ts | 44 ++++++++++++++++++++++++++++++++++++++-- 2 files changed, 48 insertions(+), 3 deletions(-) diff --git a/mongodb/mongodb-tests.ts b/mongodb/mongodb-tests.ts index 95333f78c..9cd73d073 100644 --- a/mongodb/mongodb-tests.ts +++ b/mongodb/mongodb-tests.ts @@ -21,5 +21,10 @@ MongoClient.connect('mongodb://127.0.0.1:27017/test', function (err, db) { // Let's close the db db.close(); }); + + // Get some statistics + collection.stats(function (err, stats) { + console.log(stats.count + " documents"); + }); }); -}) \ No newline at end of file +}) diff --git a/mongodb/mongodb.d.ts b/mongodb/mongodb.d.ts index a28f484ce..a1424cb7e 100644 --- a/mongodb/mongodb.d.ts +++ b/mongodb/mongodb.d.ts @@ -253,6 +253,46 @@ declare module "mongodb" { pkFactory?: PKFactory; } + // Documentation: http://docs.mongodb.org/manual/reference/command/collStats/ + export interface CollStats { + // Namespace. + ns: string; + + // Number of documents. + count: number; + + // Collection size in bytes. + size: number; + + // Average object size in bytes. + avgObjSize: number; + + // (Pre)allocated space for the collection in bytes. + storageSize: number; + + // Number of extents (contiguously allocated chunks of datafile space). + numExtents: number; + + // Number of indexes. + nindexes: number; + + // Size of the most recently created extent in bytes. + lastExtentSize: number; + + // Padding can speed up updates if documents grow. + paddingFactor: number; + flags: number; + + // Total index size in bytes. + totalIndexSize: number; + + // Size of specific indexes in bytes. + indexSizes: { + _id_: number; + username: number; + }; + } + // Documentation : http://mongodb.github.io/node-mongodb-native/api-generated/collection.html export interface Collection { new (db: Db, collectionName: string, pkFactory?: Object, options?: CollectionCreateOptions): Collection; // is this right? @@ -326,8 +366,8 @@ declare module "mongodb" { indexes(callback: Function): void; aggregate(pipeline: any[], callback: (err: Error, results: any) => void): void; aggregate(pipeline: any[], options: {readPreference: string}, callback: (err: Error, results: any) => void): void; - stats(options: {readPreference: string; scale: number}, callback: Function): void; - stats(callback: (err: Error, results: any) => void): void; + stats(options: {readPreference: string; scale: number}, callback: (err: Error, results: CollStats) => void): void; + stats(callback: (err: Error, results: CollStats) => void): void; hint: any; } From 70e3022f3ccfe17bbe853cf537b526bafc8cb014 Mon Sep 17 00:00:00 2001 From: NN Date: Tue, 10 Feb 2015 16:32:30 +0200 Subject: [PATCH 12/16] Type formData property. According to the documentation: "dictionary is present and for each key contains the list of all values for that key" . https://developer.chrome.com/extensions/webRequest --- chrome/chrome.d.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/chrome/chrome.d.ts b/chrome/chrome.d.ts index e3089152b..b3b994930 100755 --- a/chrome/chrome.d.ts +++ b/chrome/chrome.d.ts @@ -2309,10 +2309,14 @@ declare module chrome.webRequest { requestHeaders?: HttpHeader[]; } + interface FormData { + [key: string]: string[]; + } + interface RequestBody { raw?: UploadData; error?: string; - formData?: Object; + formData?: FormData; } interface OnBeforeRequestDetails extends CallbackDetails { From 137a5b8e4a2a343e051dc38462110a49affb5fa0 Mon Sep 17 00:00:00 2001 From: Eric Lu Date: Tue, 10 Feb 2015 10:51:53 -0800 Subject: [PATCH 13/16] Expose _.filter() in chained object wrapper --- lodash/lodash.d.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index 6085375c2..c8f7ad42d 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -2641,6 +2641,15 @@ declare module _ { whereValue: W): LoDashArrayWrapper; } + interface LoDashObjectWrapper { + /** + * @see _.filter + **/ + filter( + callback: ObjectIterator, + thisArg?: any): LoDashObjectWrapper; + } + //_.find interface LoDashStatic { /** From 85a4f89e8461dc424c504b5f7e7516dc105a6355 Mon Sep 17 00:00:00 2001 From: Wim Date: Wed, 11 Feb 2015 16:16:38 +1300 Subject: [PATCH 14/16] Add test for matching request header with regex --- nock/nock-tests.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/nock/nock-tests.ts b/nock/nock-tests.ts index a209a8c94..00227dfaf 100644 --- a/nock/nock-tests.ts +++ b/nock/nock-tests.ts @@ -72,7 +72,10 @@ inst = inst.twice(); inst = inst.thrice(); inst = inst.defaultReplyHeaders(value); + inst = inst.matchHeader(str, str); +inst = inst.matchHeader(str, regex); +inst = inst.matchHeader(str, (val: string) => true); inst = inst.delay(num); inst = inst.delayConnection(num); @@ -105,4 +108,4 @@ nock.recorder.rec({ }); strings = nock.recorder.play(); -objects = nock.recorder.play(); \ No newline at end of file +objects = nock.recorder.play(); From 48256bad091ea6dfaabcd7803ab70da394b46631 Mon Sep 17 00:00:00 2001 From: Wim Date: Wed, 11 Feb 2015 16:17:56 +1300 Subject: [PATCH 15/16] Add overrides for request header matching --- nock/nock.d.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/nock/nock.d.ts b/nock/nock.d.ts index bcf4560ce..db6d5df93 100644 --- a/nock/nock.d.ts +++ b/nock/nock.d.ts @@ -55,7 +55,10 @@ declare module "nock" { replyWithFile(responseCode: number, fileName: string): Scope; defaultReplyHeaders(headers: Object): Scope; + matchHeader(name: string, value: string): Scope; + matchHeader(name: string, regex: RegExp): Scope; + matchHeader(name: string, fn: (value: string) => bool): Scope; filteringPath(regex: RegExp, replace: string): Scope; filteringPath(fn: (path: string) => string): Scope; From a5b7b2c1281943248f0e2ea9f397bc657957a13b Mon Sep 17 00:00:00 2001 From: Wim Date: Wed, 11 Feb 2015 16:22:54 +1300 Subject: [PATCH 16/16] bool is not a type :( --- nock/nock.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nock/nock.d.ts b/nock/nock.d.ts index db6d5df93..b6803ca89 100644 --- a/nock/nock.d.ts +++ b/nock/nock.d.ts @@ -58,7 +58,7 @@ declare module "nock" { matchHeader(name: string, value: string): Scope; matchHeader(name: string, regex: RegExp): Scope; - matchHeader(name: string, fn: (value: string) => bool): Scope; + matchHeader(name: string, fn: (value: string) => boolean): Scope; filteringPath(regex: RegExp, replace: string): Scope; filteringPath(fn: (path: string) => string): Scope;