From 6d29b22607b6ca611a600706991755170ab73780 Mon Sep 17 00:00:00 2001 From: Daniel Phan Date: Wed, 5 Nov 2014 16:25:13 -0800 Subject: [PATCH 01/15] Add d.ts for change-case --- change-case/change-case-tests.ts | 37 ++++++++++++++++++++++++++++++++ change-case/change-case.d.ts | 37 ++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 change-case/change-case-tests.ts create mode 100644 change-case/change-case.d.ts diff --git a/change-case/change-case-tests.ts b/change-case/change-case-tests.ts new file mode 100644 index 0000000000..24276654c6 --- /dev/null +++ b/change-case/change-case-tests.ts @@ -0,0 +1,37 @@ +/// + +import changeCase = require("change-case"); + +var s: string; +var b: boolean; + +s = changeCase.dot(s); +s = changeCase.dotCase(s); +s = changeCase.swap(s); +s = changeCase.swapCase(s); +s = changeCase.path(s); +s = changeCase.pathCase(s); +s = changeCase.upper(s); +s = changeCase.upperCase(s); +s = changeCase.lower(s); +s = changeCase.lowerCase(s); +s = changeCase.camel(s); +s = changeCase.camelCase(s); +s = changeCase.snake(s); +s = changeCase.snakeCase(s); +s = changeCase.title(s); +s = changeCase.titleCase(s); +s = changeCase.param(s); +s = changeCase.paramCase(s); +s = changeCase.pascal(s); +s = changeCase.pascalCase(s); +s = changeCase.constant(s); +s = changeCase.constantCase(s); +s = changeCase.sentence(s); +s = changeCase.sentenceCase(s); +b = changeCase.isUpper(s); +b = changeCase.isUpperCase(s); +b = changeCase.isLower(s); +b = changeCase.isLowerCase(s); +s = changeCase.ucFirst(s); +s = changeCase.upperCaseFirst(s); diff --git a/change-case/change-case.d.ts b/change-case/change-case.d.ts new file mode 100644 index 0000000000..e61d70de64 --- /dev/null +++ b/change-case/change-case.d.ts @@ -0,0 +1,37 @@ +// Type definitions for change-case +// Project: https://github.com/blakeembrey/change-case +// Definitions by: Asana +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +declare module "change-case" { + function dot(s: string): string; + function dotCase(s: string): string; + function swap(s: string): string; + function swapCase(s: string): string; + function path(s: string): string; + function pathCase(s: string): string; + function upper(s: string): string; + function upperCase(s: string): string; + function lower(s: string): string; + function lowerCase(s: string): string; + function camel(s: string): string; + function camelCase(s: string): string; + function snake(s: string): string; + function snakeCase(s: string): string; + function title(s: string): string; + function titleCase(s: string): string; + function param(s: string): string; + function paramCase(s: string): string; + function pascal(s: string): string; + function pascalCase(s: string): string; + function constant(s: string): string; + function constantCase(s: string): string; + function sentence(s: string): string; + function sentenceCase(s: string): string; + function isUpper(s: string): boolean; + function isUpperCase(s: string): boolean; + function isLower(s: string): boolean; + function isLowerCase(s: string): boolean; + function ucFirst(s: string): string; + function upperCaseFirst(s: string): string; +} From e07da8a6fabb4c52295f09a65d39d86bd60fbf42 Mon Sep 17 00:00:00 2001 From: Maks3w Date: Sun, 9 Nov 2014 12:09:26 +0100 Subject: [PATCH 02/15] [jquery.validation][1.11.1] invalidElements and validElements methods --- jquery.validation/jquery.validation-tests.ts | 2 ++ jquery.validation/jquery.validation.d.ts | 2 ++ 2 files changed, 4 insertions(+) diff --git a/jquery.validation/jquery.validation-tests.ts b/jquery.validation/jquery.validation-tests.ts index 64fe6ef942..fcc22d2961 100644 --- a/jquery.validation/jquery.validation-tests.ts +++ b/jquery.validation/jquery.validation-tests.ts @@ -227,4 +227,6 @@ function test_methods() { maxlength: 5 } }); + var invalidElements: HTMLElement[] = validator.invalidElements(); + var validElements: HTMLElement[] = validator.validElements(); } diff --git a/jquery.validation/jquery.validation.d.ts b/jquery.validation/jquery.validation.d.ts index f66edadab9..916ae1016b 100644 --- a/jquery.validation/jquery.validation.d.ts +++ b/jquery.validation/jquery.validation.d.ts @@ -197,6 +197,7 @@ interface Validator * @param template The string to format. */ format(template: string, ...arguments: string[]): string; + invalidElements(): HTMLElement[]; /** * Returns the number of invalid fields. */ @@ -220,6 +221,7 @@ interface Validator showErrors(errors: any): void; hideErrors(): void; valid(): boolean; + validElements(): HTMLElement[]; size(): number; errorMap: ErrorDictionary; From 0008781fb2a165a68d10b7f579330dcb4f6a1cb6 Mon Sep 17 00:00:00 2001 From: John Vilk Date: Mon, 10 Nov 2014 12:59:50 -0500 Subject: [PATCH 03/15] Fixing type definition for semver.satisfies to return a boolean. Cleaning up type definitions a bit, and lifting function comments into JSDoc so IDEs like Visual Studio will appropriately display the comment. --- semver/semver-tests.ts | 7 +- semver/semver.d.ts | 148 +++++++++++++++++++++++++++-------------- 2 files changed, 102 insertions(+), 53 deletions(-) diff --git a/semver/semver-tests.ts b/semver/semver-tests.ts index f339be75ba..c3631cd721 100644 --- a/semver/semver-tests.ts +++ b/semver/semver-tests.ts @@ -20,10 +20,9 @@ var loose:boolean; str = mod.valid(str); str = mod.valid(str, loose); -//TODO maybe add an enum for release? str = mod.inc(str, str, loose); -//Comparison +// Comparison bool = mod.gt(v1, v2, loose); bool = mod.gte(v1, v2, loose); bool = mod.lt(v1, v2, loose); @@ -34,9 +33,9 @@ bool = mod.cmp(v1, x, v2, loose); num = mod.compare(v1, v2, loose); num = mod.rcompare(v1, v2, loose); -//Ranges +// Ranges str = mod.validRange(str, loose); -str = mod.satisfies(version, str, loose); +bool = mod.satisfies(version, str, loose); str = mod.maxSatisfying(versions, str, loose); bool = mod.gtr(version, str, loose); bool = mod.ltr(version, str, loose); diff --git a/semver/semver.d.ts b/semver/semver.d.ts index 12909d90e1..cb8efa4f50 100644 --- a/semver/semver.d.ts +++ b/semver/semver.d.ts @@ -4,72 +4,122 @@ // Definitions: https://github.com/borisyankov/DefinitelyTyped declare module SemVerModule { + /** + * Return the parsed version, or null if it's not valid. + */ + function valid(v: string, loose?: boolean): string; + /** + * Return the version incremented by the release type (major, minor, patch, or prerelease), or null if it's not valid. + */ + function inc(v: string, release: string, loose?: boolean): string; - function valid(v:string, loose?:boolean):string; // Return the parsed version, or null if it's not valid. - //TODO maybe add an enum for release? - function inc(v:string, release:string, loose?:boolean):string; // Return the version incremented by the release type (major, minor, patch, or prerelease), or null if it's not valid. + // Comparison + /** + * v1 > v2 + */ + function gt(v1: string, v2: string, loose?: boolean): boolean; + /** + * v1 >= v2 + */ + function gte(v1: string, v2: string, loose?: boolean): boolean; + /** + * v1 < v2 + */ + function lt(v1: string, v2: string, loose?: boolean): boolean; + /** + * v1 <= v2 + */ + function lte(v1: string, v2: string, loose?: boolean): boolean; + /** + * v1 == v2 This is true if they're logically equivalent, even if they're not the exact same string. You already know how to compare strings. + */ + function eq(v1: string, v2: string, loose?: boolean): boolean; + /** + * v1 != v2 The opposite of eq. + */ + function neq(v1: string, v2: string, loose?: boolean): boolean; + /** + * Pass in a comparison string, and it'll call the corresponding semver comparison function. "===" and "!==" do simple string comparison, but are included for completeness. Throws if an invalid comparison string is provided. + */ + function cmp(v1: string, comparator: any, v2: string, loose?: boolean): boolean; + /** + * Return 0 if v1 == v2, or 1 if v1 is greater, or -1 if v2 is greater. Sorts in ascending order if passed to Array.sort(). + */ + function compare(v1: string, v2: string, loose?: boolean): number; + /** + * The reverse of compare. Sorts an array of versions in descending order when passed to Array.sort(). + */ + function rcompare(v1: string, v2: string, loose?: boolean): number; - //Comparison - function gt(v1:string, v2:string, loose?:boolean):boolean; // v1 > v2 - function gte(v1:string, v2:string, loose?:boolean):boolean; // v1 >= v2 - function lt(v1:string, v2:string, loose?:boolean):boolean; // v1 < v2 - function lte(v1:string, v2:string, loose?:boolean):boolean; // v1 <= v2 - function eq(v1:string, v2:string, loose?:boolean):boolean; // v1 == v2 This is true if they're logically equivalent, even if they're not the exact same string. You already know how to compare strings. - function neq(v1:string, v2:string, loose?:boolean):boolean; // v1 != v2 The opposite of eq. - function cmp(v1:string, comparator:any, v2:string, loose?:boolean):boolean; // Pass in a comparison string, and it'll call the corresponding function above. "===" and "!==" do simple string comparison, but are included for completeness. Throws if an invalid comparison string is provided. - function compare(v1:string, v2:string, loose?:boolean):number; // Return 0 if v1 == v2, or 1 if v1 is greater, or -1 if v2 is greater. Sorts in ascending order if passed to Array.sort(). - function rcompare(v1:string, v2:string, loose?:boolean):number; // The reverse of compare. Sorts an array of versions in descending order when passed to Array.sort(). - - //Ranges - function validRange(range:string, loose?:boolean):string; // Return the valid range or null if it's not valid - function satisfies(version:string, range:string, loose?:boolean):string; // Return true if the version satisfies the range. - function maxSatisfying(versions:string[], range:string, loose?:boolean):string; // Return the highest version in the list that satisfies the range, or null if none of them do. - function gtr(version:string, range:string, loose?:boolean):boolean; // Return true if version is greater than all the versions possible in the range. - function ltr(version:string, range:string, loose?:boolean):boolean; // Return true if version is less than all the versions possible in the range. - function outside(version:string, range:string, hilo:string, loose?:boolean):boolean; // Return true if the version is outside the bounds of the range in either the high or low direction. The hilo argument must be either the string '>' or '<'. (This is the function called by gtr and ltr.) + // Ranges + /** + * Return the valid range or null if it's not valid + */ + function validRange(range: string, loose?: boolean): string; + /** + * Return true if the version satisfies the range. + */ + function satisfies(version: string, range: string, loose?: boolean): boolean; + /** + * Return the highest version in the list that satisfies the range, or null if none of them do. + */ + function maxSatisfying(versions: string[], range: string, loose?: boolean): string; + /** + * Return true if version is greater than all the versions possible in the range. + */ + function gtr(version: string, range: string, loose?: boolean): boolean; + /** + * Return true if version is less than all the versions possible in the range. + */ + function ltr(version: string, range: string, loose?: boolean): boolean; + /** + * Return true if the version is outside the bounds of the range in either the high or low direction. The hilo argument must be either the string '>' or '<'. (This is the function called by gtr and ltr.) + */ + function outside(version: string, range: string, hilo: string, loose?: boolean): boolean; class SemVerBase { - raw:string; - loose:boolean; - format():string; - inspect():string; - toString():string; + raw: string; + loose: boolean; + format(): string; + inspect(): string; + toString(): string; } - class SemVer extends SemVerBase { - constructor(version:string, loose?:boolean); + class SemVer extends SemVerBase { + constructor(version: string, loose?: boolean); - major:number; - minor:number; - patch:number; - version:string; - build:string[]; - prerelease:string[]; + major: number; + minor: number; + patch: number; + version: string; + build: string[]; + prerelease: string[]; - compare(other:SemVer):number; - compareMain(other:SemVer):number; - comparePre(other:SemVer):number; - inc(release:string):SemVer; + compare(other:SemVer): number; + compareMain(other:SemVer): number; + comparePre(other:SemVer): number; + inc(release: string): SemVer; } class Comparator extends SemVerBase { - constructor(comp:string, loose?:boolean); + constructor(comp: string, loose?: boolean); - semver:SemVer; - operator:string; - value:boolean; - parse(comp:string) :void; - test(version:SemVer):boolean; + semver: SemVer; + operator: string; + value: boolean; + parse(comp: string): void; + test(version:SemVer): boolean; } class Range extends SemVerBase { - constructor(range:string, loose?:boolean); + constructor(range: string, loose?: boolean); - set:Comparator[][]; - parseRange(range:string):Comparator[]; - test(version:SemVer):boolean; + set: Comparator[][]; + parseRange(range: string): Comparator[]; + test(version: SemVer): boolean; } } + declare module "semver" { -export = SemVerModule; + export = SemVerModule; } From 64d394d81a74bf817515f323bf22dfcc26426870 Mon Sep 17 00:00:00 2001 From: John Vilk Date: Mon, 10 Nov 2014 13:16:30 -0500 Subject: [PATCH 04/15] Fixing tar.Pack to have an optional properties parameter. Adding in some JSDoc for the main methods, lifted directly from documentation, and adding a TODO for the future if someone decides to type the fstream library. --- tar/tar-tests.ts | 11 +++++++---- tar/tar.d.ts | 33 +++++++++++++++++++++++++++------ 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/tar/tar-tests.ts b/tar/tar-tests.ts index 3a7783d521..b23ad7d06b 100644 --- a/tar/tar-tests.ts +++ b/tar/tar-tests.ts @@ -1,8 +1,8 @@ /** -* Test suite created by Maxime LUCE -* -* Created by using code samples from https://github.com/npm/node-tar. -*/ + * Test suite created by Maxime LUCE + * + * Created by using code samples from https://github.com/npm/node-tar. + */ /// /// @@ -26,3 +26,6 @@ readStream.pipe(extract); extract.on("entry", (entry: any) => { }); + +var packStream: tar.PackStream = tar.Pack(); +packStream = tar.Pack({ path: 'test' }); diff --git a/tar/tar.d.ts b/tar/tar.d.ts index 6b25a02a78..3116b5cc9e 100644 --- a/tar/tar.d.ts +++ b/tar/tar.d.ts @@ -2,13 +2,14 @@ // Project: https://github.com/npm/node-tar // Definitions by: Maxime LUCE // Definitions: https://github.com/borisyankov/DefinitelyTyped +// TODO: When/if typings for [fstream](https://github.com/npm/fstream) are written, refactor this typing to use it for the various streams. /// declare module "tar" { import stream = require("stream"); - //#region Interfaces + // #region Interfaces export interface HeaderProperties { path?: string; @@ -64,9 +65,9 @@ declare module "tar" { export interface ExtractStream extends ParseStream { } - //#endregion + // #endregion - //#region Enums + // #region Enums export var fields: { path: number; @@ -198,11 +199,31 @@ declare module "tar" { //#region Global Methods + /** + * Returns a writable stream. Write tar data to it and it will emit entry events for each entry parsed from the tarball. This is used by tar.Extract. + */ export function Parse(): ParseStream; - - export function Pack(props: HeaderProperties): PackStream; - + /** + * Returns a through stream. Use fstream to write files into the pack stream and you will receive tar archive data from the pack stream. + * This only works with directories, it does not work with individual files. + * The optional properties object are used to set properties in the tar 'Global Extended Header'. + */ + export function Pack(props?: HeaderProperties): PackStream; + /** + * Returns a through stream. Write tar data to the stream and the files in the tarball will be extracted onto the filesystem. + */ export function Extract(path: string): ExtractStream; + /** + * Returns a through stream. Write tar data to the stream and the files in the tarball will be extracted onto the filesystem. + * options can be: + * ``` + * { + * path: '/path/to/extract/tar/into', + * strip: 0, // how many path segments to strip from the root when extracting + * } + * ``` + * options also get passed to the fstream.Writer instance that tar uses internally. + */ export function Extract(opts: ExtractOptions): ExtractStream; //#endregion From 9cd13294ae6c8b16ea7595e2ca0ce12e04ece6bd Mon Sep 17 00:00:00 2001 From: Chris Martinez Date: Tue, 11 Nov 2014 12:24:13 -0500 Subject: [PATCH 05/15] Added lscache definition Added lscache definition --- CONTRIBUTORS.md | 3 ++- lscache/lscache-tests.ts | 13 +++++++++++++ lscache/lscache.d.ts | 13 +++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 lscache/lscache-tests.ts create mode 100644 lscache/lscache.d.ts diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index a628bd4814..e10ca14d4c 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -1,4 +1,4 @@ -# Contributors +# Contributors This is a non-exhaustive list of definitions and their creators. If you created a definition but are not listed then feel free to send a pull request on this file with your name and url. @@ -270,6 +270,7 @@ All definitions files include a header with the author and editors, so at some p * [Lodash](http://lodash.com/) (by [Brian Zengel](https://github.com/bczengel)) * [Logg](https://github.com/dpup/node-logg) (by [Bret Little](https://github.com/blittle)) * [Long.js](https://github.com/dcodeIO/Long.js) (by [Toshihide Hara](https://github.com/kerug)) +* [lscache](https://github.com/pamelafox/lscache) (by [Chris Martinez](https://github.com/Chris-Martinezz)) * [lz-string](https://github.com/pieroxy/lz-string) (by [Roman Nikitin](https://github.com/M0ns1gn0r)) * [Mapbox](https://github.com/mapbox/mapbox.js/) (by [Maxime Fabre](https://github.com/anahkiasen)) * [Marked](https://github.com/chjj/marked) (by [William Orr](https://github.com/worr)) diff --git a/lscache/lscache-tests.ts b/lscache/lscache-tests.ts new file mode 100644 index 0000000000..103cb6c8c9 --- /dev/null +++ b/lscache/lscache-tests.ts @@ -0,0 +1,13 @@ +/// + +// Copied examples directly from lscache github site with slight modifications + +lscache.set('greeting', 'Hello World!', 2); + +alert(lscache.get('greeting')); + +lscache.remove('greeting'); + +lscache.set('data', { 'name': 'Pamela', 'age': 26 }, 2); + +alert(lscache.get('data').name); \ No newline at end of file diff --git a/lscache/lscache.d.ts b/lscache/lscache.d.ts new file mode 100644 index 0000000000..777c89421c --- /dev/null +++ b/lscache/lscache.d.ts @@ -0,0 +1,13 @@ +// Type definitions for lscache v1.0.2 +// Project: https://github.com/pamelafox/lscache +// Definitions by: Chris Martinez https://github.com/Chris-Martinezz +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +interface LSCache { + + set(key: string, value: any, time?: number): void; + get(key: string): any; + remove(key: string): void; +} + +declare var lscache: LSCache; \ No newline at end of file From 49e799b01b777784efd569212788e8baf2c40a58 Mon Sep 17 00:00:00 2001 From: Chris Martinez Date: Tue, 11 Nov 2014 12:33:12 -0500 Subject: [PATCH 06/15] Fix lscache header Fix lscache header so npm test passes. --- lscache/lscache.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lscache/lscache.d.ts b/lscache/lscache.d.ts index 777c89421c..24c34bd8da 100644 --- a/lscache/lscache.d.ts +++ b/lscache/lscache.d.ts @@ -1,6 +1,6 @@ // Type definitions for lscache v1.0.2 // Project: https://github.com/pamelafox/lscache -// Definitions by: Chris Martinez https://github.com/Chris-Martinezz +// Definitions by: Chris Martinez // Definitions: https://github.com/borisyankov/DefinitelyTyped interface LSCache { From 792d0aa3c97d6367d5494bdc36f531c32bd8f296 Mon Sep 17 00:00:00 2001 From: "Yubing (Tom) Dong" Date: Tue, 11 Nov 2014 17:22:07 -0800 Subject: [PATCH 07/15] TrackballControls should extend EventDispatcher (threejs) Please see https://github.com/mrdoob/three.js/blob/master/examples/js/controls/Trac kballControls.js#L611 The prototype of THREE.TrackballControls is THREE.EventDispatcher.prototype. --- threejs/three-trackballcontrols.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/threejs/three-trackballcontrols.d.ts b/threejs/three-trackballcontrols.d.ts index b4bda75ee9..ad6ffa9c36 100644 --- a/threejs/three-trackballcontrols.d.ts +++ b/threejs/three-trackballcontrols.d.ts @@ -6,7 +6,7 @@ /// declare module THREE { - class TrackballControls { + class TrackballControls extends EventDispatcher { constructor(object:Camera, domElement?:HTMLElement); object:Camera; From eb3420c93c76638aadf8a5a6456f06611d4b061e Mon Sep 17 00:00:00 2001 From: Paulo Cesar Date: Wed, 12 Nov 2014 01:57:38 -0200 Subject: [PATCH 08/15] update angular to released version 1.3+ --- .gitignore | 2 + angularjs/angular-cookies.d.ts | 4 +- angularjs/angular-tests.ts | 43 +++++++++- angularjs/angular.d.ts | 141 +++++++++++++++++++++++++-------- 4 files changed, 157 insertions(+), 33 deletions(-) diff --git a/.gitignore b/.gitignore index d4bc5dd91f..bbbef03572 100644 --- a/.gitignore +++ b/.gitignore @@ -33,3 +33,5 @@ _infrastructure/tests/build !rx.js node_modules + +.sublimets diff --git a/angularjs/angular-cookies.d.ts b/angularjs/angular-cookies.d.ts index dc0c449089..0feffae83a 100644 --- a/angularjs/angular-cookies.d.ts +++ b/angularjs/angular-cookies.d.ts @@ -15,7 +15,9 @@ declare module ng.cookies { // CookieService // see http://docs.angularjs.org/api/ngCookies.$cookies /////////////////////////////////////////////////////////////////////////// - interface ICookiesService {} + interface ICookiesService { + [index: string]: any; + } /////////////////////////////////////////////////////////////////////////// // CookieStoreService diff --git a/angularjs/angular-tests.ts b/angularjs/angular-tests.ts index 7adb0bab0b..628b6d1d25 100644 --- a/angularjs/angular-tests.ts +++ b/angularjs/angular-tests.ts @@ -83,7 +83,7 @@ angular.module('http-auth-interceptor', []) } }]; - $httpProvider.responseInterceptors.push(interceptor); + $httpProvider.interceptors.push(interceptor); }]); @@ -326,6 +326,47 @@ class SampleDirective2 implements ng.IDirective { angular.module('SameplDirective', []).directive('sampleDirective', SampleDirective.instance).directive('sameplDirective2', SampleDirective2.instance); +angular.module('AnotherSampleDirective', []).directive('myDirective', ['$interpolate', '$q', ($interpolate: ng.IInterpolateService, $q: ng.IQService) => { + return { + restrict: 'A', + link: (scope: ng.IScope, el: ng.IAugmentedJQuery, attr: ng.IAttributes) => { + $interpolate(attr['test'])(scope); + $interpolate('', true)(scope); + $interpolate('', true, 'html')(scope); + $interpolate('', true, 'html', true)(scope); + var defer = $q.defer(); + defer.reject(); + defer.resolve(); + defer.promise.then(function(d) { + return d; + }).then(function(): any { + return null; + }, function(): any { + return null; + }) + .catch((): any => { + return null; + }) + .finally((): any => { + return null; + }); + var promise = new $q((resolve) => { + resolve(); + }); + + promise = new $q((resolve, reject) => { + reject(); + resolve(true); + }); + + promise = new $q((resolver, reject) => { + resolver(true); + reject(false); + }); + } + }; +}]); + // test from https://docs.angularjs.org/guide/directive angular.module('docsSimpleDirective', []) .controller('Controller', ['$scope', function($scope: any) { diff --git a/angularjs/angular.d.ts b/angularjs/angular.d.ts index 4659da7612..b5cc51dafa 100755 --- a/angularjs/angular.d.ts +++ b/angularjs/angular.d.ts @@ -13,6 +13,11 @@ interface Function { $inject?: string[]; } +// Support AMD require +declare module 'angular' { + export = angular; +} + /////////////////////////////////////////////////////////////////////////////// // ng module (angular.js) /////////////////////////////////////////////////////////////////////////////// @@ -32,6 +37,10 @@ declare module ng { $get: any; } + interface IAngularBootstrapConfig { + strictDi?: boolean; + } + /////////////////////////////////////////////////////////////////////////// // AngularStatic // see http://docs.angularjs.org/api @@ -46,8 +55,10 @@ declare module ng { * @param modules An array of modules to load into the application. * Each item in the array should be the name of a predefined module or a (DI annotated) * function that will be invoked by the injector as a run block. + * @param config an object for defining configuration options for the application. The following keys are supported: + * - `strictDi`: disable automatic function annotation for the application. This is meant to assist in finding bugs which break minified code. */ - bootstrap(element: string, modules?: string): auto.IInjectorService; + bootstrap(element: string, modules?: string, config?: IAngularBootstrapConfig): auto.IInjectorService; /** * Use this function to manually start up angular application. * @@ -55,8 +66,10 @@ declare module ng { * @param modules An array of modules to load into the application. * Each item in the array should be the name of a predefined module or a (DI annotated) * function that will be invoked by the injector as a run block. + * @param config an object for defining configuration options for the application. The following keys are supported: + * - `strictDi`: disable automatic function annotation for the application. This is meant to assist in finding bugs which break minified code. */ - bootstrap(element: string, modules?: Function): auto.IInjectorService; + bootstrap(element: string, modules?: Function, config?: IAngularBootstrapConfig): auto.IInjectorService; /** * Use this function to manually start up angular application. * @@ -64,8 +77,10 @@ declare module ng { * @param modules An array of modules to load into the application. * Each item in the array should be the name of a predefined module or a (DI annotated) * function that will be invoked by the injector as a run block. + * @param config an object for defining configuration options for the application. The following keys are supported: + * - `strictDi`: disable automatic function annotation for the application. This is meant to assist in finding bugs which break minified code. */ - bootstrap(element: string, modules?: string[]): auto.IInjectorService; + bootstrap(element: string, modules?: string[], config?: IAngularBootstrapConfig): auto.IInjectorService; /** * Use this function to manually start up angular application. * @@ -73,8 +88,10 @@ declare module ng { * @param modules An array of modules to load into the application. * Each item in the array should be the name of a predefined module or a (DI annotated) * function that will be invoked by the injector as a run block. + * @param config an object for defining configuration options for the application. The following keys are supported: + * - `strictDi`: disable automatic function annotation for the application. This is meant to assist in finding bugs which break minified code. */ - bootstrap(element: JQuery, modules?: string): auto.IInjectorService; + bootstrap(element: JQuery, modules?: string, config?: IAngularBootstrapConfig): auto.IInjectorService; /** * Use this function to manually start up angular application. * @@ -82,8 +99,10 @@ declare module ng { * @param modules An array of modules to load into the application. * Each item in the array should be the name of a predefined module or a (DI annotated) * function that will be invoked by the injector as a run block. + * @param config an object for defining configuration options for the application. The following keys are supported: + * - `strictDi`: disable automatic function annotation for the application. This is meant to assist in finding bugs which break minified code. */ - bootstrap(element: JQuery, modules?: Function): auto.IInjectorService; + bootstrap(element: JQuery, modules?: Function, config?: IAngularBootstrapConfig): auto.IInjectorService; /** * Use this function to manually start up angular application. * @@ -91,8 +110,10 @@ declare module ng { * @param modules An array of modules to load into the application. * Each item in the array should be the name of a predefined module or a (DI annotated) * function that will be invoked by the injector as a run block. + * @param config an object for defining configuration options for the application. The following keys are supported: + * - `strictDi`: disable automatic function annotation for the application. This is meant to assist in finding bugs which break minified code. */ - bootstrap(element: JQuery, modules?: string[]): auto.IInjectorService; + bootstrap(element: JQuery, modules?: string[], config?: IAngularBootstrapConfig): auto.IInjectorService; /** * Use this function to manually start up angular application. * @@ -100,8 +121,10 @@ declare module ng { * @param modules An array of modules to load into the application. * Each item in the array should be the name of a predefined module or a (DI annotated) * function that will be invoked by the injector as a run block. + * @param config an object for defining configuration options for the application. The following keys are supported: + * - `strictDi`: disable automatic function annotation for the application. This is meant to assist in finding bugs which break minified code. */ - bootstrap(element: Element, modules?: string): auto.IInjectorService; + bootstrap(element: Element, modules?: string, config?: IAngularBootstrapConfig): auto.IInjectorService; /** * Use this function to manually start up angular application. * @@ -109,8 +132,10 @@ declare module ng { * @param modules An array of modules to load into the application. * Each item in the array should be the name of a predefined module or a (DI annotated) * function that will be invoked by the injector as a run block. + * @param config an object for defining configuration options for the application. The following keys are supported: + * - `strictDi`: disable automatic function annotation for the application. This is meant to assist in finding bugs which break minified code. */ - bootstrap(element: Element, modules?: Function): auto.IInjectorService; + bootstrap(element: Element, modules?: Function, config?: IAngularBootstrapConfig): auto.IInjectorService; /** * Use this function to manually start up angular application. * @@ -118,8 +143,10 @@ declare module ng { * @param modules An array of modules to load into the application. * Each item in the array should be the name of a predefined module or a (DI annotated) * function that will be invoked by the injector as a run block. + * @param config an object for defining configuration options for the application. The following keys are supported: + * - `strictDi`: disable automatic function annotation for the application. This is meant to assist in finding bugs which break minified code. */ - bootstrap(element: Element, modules?: string[]): auto.IInjectorService; + bootstrap(element: Element, modules?: string[], config?: IAngularBootstrapConfig): auto.IInjectorService; /** * Use this function to manually start up angular application. * @@ -127,8 +154,10 @@ declare module ng { * @param modules An array of modules to load into the application. * Each item in the array should be the name of a predefined module or a (DI annotated) * function that will be invoked by the injector as a run block. + * @param config an object for defining configuration options for the application. The following keys are supported: + * - `strictDi`: disable automatic function annotation for the application. This is meant to assist in finding bugs which break minified code. */ - bootstrap(element: Document, modules?: string): auto.IInjectorService; + bootstrap(element: Document, modules?: string, config?: IAngularBootstrapConfig): auto.IInjectorService; /** * Use this function to manually start up angular application. * @@ -136,8 +165,10 @@ declare module ng { * @param modules An array of modules to load into the application. * Each item in the array should be the name of a predefined module or a (DI annotated) * function that will be invoked by the injector as a run block. + * @param config an object for defining configuration options for the application. The following keys are supported: + * - `strictDi`: disable automatic function annotation for the application. This is meant to assist in finding bugs which break minified code. */ - bootstrap(element: Document, modules?: Function): auto.IInjectorService; + bootstrap(element: Document, modules?: Function, config?: IAngularBootstrapConfig): auto.IInjectorService; /** * Use this function to manually start up angular application. * @@ -145,8 +176,10 @@ declare module ng { * @param modules An array of modules to load into the application. * Each item in the array should be the name of a predefined module or a (DI annotated) * function that will be invoked by the injector as a run block. + * @param config an object for defining configuration options for the application. The following keys are supported: + * - `strictDi`: disable automatic function annotation for the application. This is meant to assist in finding bugs which break minified code. */ - bootstrap(element: Document, modules?: string[]): auto.IInjectorService; + bootstrap(element: Document, modules?: string[], config?: IAngularBootstrapConfig): auto.IInjectorService; /** * Creates a deep copy of source, which should be an object or an array. @@ -230,6 +263,7 @@ declare module ng { configFn?: Function): IModule; noop(...args: any[]): void; + reloadWithDebugInfo(): void; toJson(obj: any, pretty?: boolean): string; uppercase(str: string): string; version: { @@ -412,6 +446,7 @@ declare module ng { $commitViewValue(): void; $rollbackViewValue(): void; $setSubmitted(): void; + $setUntouched(): void; } /////////////////////////////////////////////////////////////////////////// @@ -423,13 +458,13 @@ declare module ng { $setValidity(validationErrorKey: string, isValid: boolean): void; // Documentation states viewValue and modelValue to be a string but other // types do work and it's common to use them. - $setViewValue(value: any): void; + $setViewValue(value: any, trigger?: string): void; $setPristine(): void; $validate(): void; $setTouched(): void; $setUntouched(): void; $rollbackViewValue(): void; - $commitViewValue(revalidate?: boolean): void; + $commitViewValue(): void; $isEmpty(value: any): boolean; $viewValue: any; @@ -448,6 +483,7 @@ declare module ng { $validators: IModelValidators; $asyncValidators: IAsyncModelValidators; + $pending: any; $pristine: boolean; $dirty: boolean; $valid: boolean; @@ -479,10 +515,13 @@ declare module ng { * see https://docs.angularjs.org/api/ng/type/$rootScope.Scope and https://docs.angularjs.org/api/ng/service/$rootScope */ interface IRootScopeService { + [index: string]: any; + $apply(): any; $apply(exp: string): any; $apply(exp: (scope: IScope) => any): any; - + + $applyAsync(): any; $applyAsync(exp: string): any; $applyAsync(exp: (scope: IScope) => any): any; @@ -491,14 +530,20 @@ declare module ng { $digest(): void; $emit(name: string, ...args: any[]): IAngularEvent; - $eval(expression?: string, args?: Object): any; - $eval(expression?: (scope: IScope) => any, args?: Object): any; + $eval(): any; + $eval(expression: string): any; + $eval(expression: string, locals: Object): any; + $eval(expression: (scope: IScope) => any): any; + $eval(expression: (scope: IScope) => any, locals: Object): any; - $evalAsync(expression?: string): void; - $evalAsync(expression?: (scope: IScope) => any): void; + $evalAsync(): void; + $evalAsync(expression: string): void; + $evalAsync(expression: (scope: IScope) => any): void; // Defaults to false by the implementation checking strategy - $new(isolate?: boolean): IScope; + $new(): IScope; + $new(isolate: boolean): IScope; + $new(isolate: boolean, parent: IScope): IScope; /** * Listens on events of a given type. See $emit for discussion of event life cycle. @@ -522,10 +567,7 @@ declare module ng { $watchGroup(watchExpressions: { (scope: IScope): any }[], listener: (newValue: any, oldValue: any, scope: IScope) => any): Function; $parent: IScope; - $root: IRootScopeService; - this: IRootScopeService; - $id: number; // Hidden members @@ -533,9 +575,7 @@ declare module ng { $$phase: any; } - interface IScope extends IRootScopeService { - [index: string]: any; - } + interface IScope extends IRootScopeService { } interface IAngularEvent { /** @@ -585,7 +625,9 @@ declare module ng { // see http://docs.angularjs.org/api/ng.$timeout /////////////////////////////////////////////////////////////////////////// interface ITimeoutService { - (func: Function, delay?: number, invokeApply?: boolean): IPromise; + (func: Function): IPromise; + (func: Function, delay: number): IPromise; + (func: Function, delay: number, invokeApply: boolean): IPromise; cancel(promise: IPromise): boolean; } @@ -594,7 +636,9 @@ declare module ng { // see http://docs.angularjs.org/api/ng.$interval /////////////////////////////////////////////////////////////////////////// interface IIntervalService { - (func: Function, delay: number, count?: number, invokeApply?: boolean): IPromise; + (func: Function, delay: number): IPromise; + (func: Function, delay: number, count: number): IPromise; + (func: Function, delay: number, count: number, invokeApply: boolean): IPromise; cancel(promise: IPromise): boolean; } @@ -812,6 +856,8 @@ declare module ng { */ search(search: string, paramValue: boolean): ILocationService; + state(): any; + state(state: any): ILocationService; url(): string; url(url: string): ILocationService; } @@ -847,12 +893,20 @@ declare module ng { /////////////////////////////////////////////////////////////////////////// interface IRootElementService extends JQuery {} + interface IQResolveReject { + (): void; + (value: T): void; + } /** * $q - service in module ng * A promise/deferred implementation inspired by Kris Kowal's Q. * See http://docs.angularjs.org/api/ng/service/$q */ interface IQService { + new (resolver: (resolve: IQResolveReject) => any): IPromise; + new (resolver: (resolve: IQResolveReject, reject: IQResolveReject) => any): IPromise; + new (resolver: (resolve: IQResolveReject, reject: IQResolveReject) => any): IPromise; + /** * Combines multiple promises into a single promise that is resolved when all of the input promises are resolved. * @@ -955,6 +1009,7 @@ declare module ng { /////////////////////////////////////////////////////////////////////////// interface IAnchorScrollService { (): void; + yOffset: any; } interface IAnchorScrollProvider extends IServiceProvider { @@ -1014,6 +1069,9 @@ declare module ng { imgSrcSanitizationWhitelist(): RegExp; imgSrcSanitizationWhitelist(regexp: RegExp): ICompileProvider; + + debugInfoEnabled(): any; + debugInfoEnabled(enabled: boolean): any; } interface ICloneAttachFunction { @@ -1048,6 +1106,7 @@ declare module ng { interface IControllerProvider extends IServiceProvider { register(name: string, controllerConstructor: Function): void; register(name: string, dependencyAnnotatedConstructor: any[]): void; + allowGlobals(): void; } /** @@ -1227,10 +1286,22 @@ declare module ng { then(successCallback: (response: IHttpPromiseCallbackArg) => TResult, errorCallback?: (response: IHttpPromiseCallbackArg) => any): IPromise; } + interface IHttpProviderDefaults { + xsrfCookieName?: string; + xsrfHeaderName?: string; + headers?: { + common?: any; + post?: any; + put?: any; + patch?: any; + } + } + interface IHttpProvider extends IServiceProvider { - defaults: IRequestConfig; + defaults: IHttpProviderDefaults; interceptors: any[]; - responseInterceptors: any[]; + useApplyAsync(): boolean; + useApplyAsync(value: boolean): IHttpProvider; } /////////////////////////////////////////////////////////////////////////// @@ -1249,7 +1320,10 @@ declare module ng { // see http://docs.angularjs.org/api/ng.$interpolateProvider /////////////////////////////////////////////////////////////////////////// interface IInterpolateService { - (text: string, mustHaveExpression?: boolean): IInterpolationFunction; + (text: string): IInterpolationFunction; + (text: string, mustHaveExpression: boolean): IInterpolationFunction; + (text: string, mustHaveExpression: boolean, trustedContext: string): IInterpolationFunction; + (text: string, mustHaveExpression: boolean, trustedContext: string, allOrNothing: boolean): IInterpolationFunction; endSymbol(): string; startSymbol(): string; } @@ -1345,6 +1419,11 @@ declare module ng { * @return A promise whose value is the template content. */ (tpl: string, ignoreRequestError?: boolean): IPromise; + /** + * total amount of pending template requests being downloaded. + * @type {number} + */ + totalPendingRequests: number; } /////////////////////////////////////////////////////////////////////////// From 91ea0ef4cec935d3777ff805f8beea695be98364 Mon Sep 17 00:00:00 2001 From: Paulo Cesar Date: Wed, 12 Nov 2014 06:04:00 -0200 Subject: [PATCH 09/15] squash! update angular to released version 1.3+ undo optionals --- angularjs/angular.d.ts | 32 ++++++++++---------------------- 1 file changed, 10 insertions(+), 22 deletions(-) diff --git a/angularjs/angular.d.ts b/angularjs/angular.d.ts index b5cc51dafa..d28c40e21e 100755 --- a/angularjs/angular.d.ts +++ b/angularjs/angular.d.ts @@ -531,19 +531,15 @@ declare module ng { $emit(name: string, ...args: any[]): IAngularEvent; $eval(): any; - $eval(expression: string): any; - $eval(expression: string, locals: Object): any; - $eval(expression: (scope: IScope) => any): any; - $eval(expression: (scope: IScope) => any, locals: Object): any; + $eval(expression: string, locals?: Object): any; + $eval(expression: (scope: IScope) => any, locals?: Object): any; $evalAsync(): void; $evalAsync(expression: string): void; $evalAsync(expression: (scope: IScope) => any): void; // Defaults to false by the implementation checking strategy - $new(): IScope; - $new(isolate: boolean): IScope; - $new(isolate: boolean, parent: IScope): IScope; + $new(isolate?: boolean, parent?: IScope): IScope; /** * Listens on events of a given type. See $emit for discussion of event life cycle. @@ -625,9 +621,7 @@ declare module ng { // see http://docs.angularjs.org/api/ng.$timeout /////////////////////////////////////////////////////////////////////////// interface ITimeoutService { - (func: Function): IPromise; - (func: Function, delay: number): IPromise; - (func: Function, delay: number, invokeApply: boolean): IPromise; + (func: Function, delay?: number, invokeApply?: boolean): IPromise; cancel(promise: IPromise): boolean; } @@ -636,9 +630,7 @@ declare module ng { // see http://docs.angularjs.org/api/ng.$interval /////////////////////////////////////////////////////////////////////////// interface IIntervalService { - (func: Function, delay: number): IPromise; - (func: Function, delay: number, count: number): IPromise; - (func: Function, delay: number, count: number, invokeApply: boolean): IPromise; + (func: Function, delay?: number, count?: number, invokeApply?: boolean): IPromise; cancel(promise: IPromise): boolean; } @@ -747,8 +739,8 @@ declare module ng { } interface ILogProvider { - debugEnabled(enabled: boolean): ILogProvider; debugEnabled(): boolean; + debugEnabled(enabled: boolean): ILogProvider; } // We define this as separete interface so we can reopen it later for @@ -1070,8 +1062,7 @@ declare module ng { imgSrcSanitizationWhitelist(): RegExp; imgSrcSanitizationWhitelist(regexp: RegExp): ICompileProvider; - debugInfoEnabled(): any; - debugInfoEnabled(enabled: boolean): any; + debugInfoEnabled(enabled?: boolean): any; } interface ICloneAttachFunction { @@ -1320,10 +1311,7 @@ declare module ng { // see http://docs.angularjs.org/api/ng.$interpolateProvider /////////////////////////////////////////////////////////////////////////// interface IInterpolateService { - (text: string): IInterpolationFunction; - (text: string, mustHaveExpression: boolean): IInterpolationFunction; - (text: string, mustHaveExpression: boolean, trustedContext: string): IInterpolationFunction; - (text: string, mustHaveExpression: boolean, trustedContext: string, allOrNothing: boolean): IInterpolationFunction; + (text: string, mustHaveExpression?: boolean, trustedContext?: string, allOrNothing?: boolean): IInterpolationFunction; endSymbol(): string; startSymbol(): string; } @@ -1443,7 +1431,7 @@ declare module ng { instanceAttributes: IAttributes, controller: any, transclude: ITranscludeFunction - ): void; + ): void; } interface IDirectivePrePost { @@ -1456,7 +1444,7 @@ declare module ng { templateElement: IAugmentedJQuery, templateAttributes: IAttributes, transclude: ITranscludeFunction - ): IDirectivePrePost; + ): IDirectivePrePost; } interface IDirective { From a3b4851dfce1ae035e0e57b18673f4cd65f25b1e Mon Sep 17 00:00:00 2001 From: Martin Poelstra Date: Wed, 12 Nov 2014 11:19:15 +0100 Subject: [PATCH 10/15] Update Bluebird typings to 2.x and fix some issues: - 'Old' typings moved to "-1.0" version - Not all v2 methods are added yet - Promise also implements Inspection - .finally() doesn't get the value in its callback - .done() returns void, not a Promise - Add .tap() and .setScheduler() - Add error types for use in e.g. catch()'ing specific errors - Inspection.error() renamed to .reason() --- bluebird/bluebird-1.0-tests.ts | 882 +++++++++++++++++++++++++++++++++ bluebird/bluebird-1.0.d.ts | 670 +++++++++++++++++++++++++ bluebird/bluebird-tests.ts | 73 +-- bluebird/bluebird.d.ts | 64 ++- 4 files changed, 1648 insertions(+), 41 deletions(-) create mode 100644 bluebird/bluebird-1.0-tests.ts create mode 100644 bluebird/bluebird-1.0.d.ts diff --git a/bluebird/bluebird-1.0-tests.ts b/bluebird/bluebird-1.0-tests.ts new file mode 100644 index 0000000000..f04317f6ae --- /dev/null +++ b/bluebird/bluebird-1.0-tests.ts @@ -0,0 +1,882 @@ +/// + +// Tests by: Bart van der Schoor + +// Note: replicate changes to all overloads in both definition and test file +// Note: keep both static and instance members inline (so similar) + +// Note: try to maintain the ordering and separators, and keep to the pattern + +var obj: Object; +var bool: boolean; +var num: number; +var str: string; +var err: Error; +var x: any; +var f: Function; +var func: Function; +var arr: any[]; +var exp: RegExp; +var anyArr: any[]; +var strArr: string[]; +var numArr: number[]; + +// - - - - - - - - - - - - - - - - - + +var value: any; +var reason: any; +var insanity: any; + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +interface Foo { + foo(): string; +} +interface Bar { + bar(): string; +} + +// - - - - - - - - - - - - - - - - - + +interface StrFooMap { + [key:string]:Foo; +} + +interface StrBarMap { + [key:string]:Bar; +} + +// - - - - - - - - - - - - - - - - - + +interface StrFooArrMap { + [key:string]:Foo[]; +} + +interface StrBarArrMap { + [key:string]:Bar[]; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +var foo: Foo; +var bar: Bar; + +var fooArr: Foo[]; +var barArr: Bar[]; + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +var numProm: Promise; +var strProm: Promise; +var anyProm: Promise; +var boolProm: Promise; +var objProm: Promise; +var voidProm: Promise; + +var fooProm: Promise; +var barProm: Promise; + +// - - - - - - - - - - - - - - - - - + +var numThen: Promise.Thenable; +var strThen: Promise.Thenable; +var anyThen: Promise.Thenable; +var boolThen: Promise.Thenable; +var objThen: Promise.Thenable; +var voidThen: Promise.Thenable; + +var fooThen: Promise.Thenable; +var barThen: Promise.Thenable; + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +var numArrProm: Promise; +var strArrProm: Promise; +var anyArrProm: Promise; + +var fooArrProm: Promise; +var barArrProm: Promise; + +// - - - - - - - - - - - - - - - - - + +var numArrThen: Promise.Thenable; +var strArrThen: Promise.Thenable; +var anyArrThen: Promise.Thenable; + +var fooArrThen: Promise.Thenable; +var barArrThen: Promise.Thenable; + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +var numPromArr: Promise[]; +var strPromArr: Promise[]; +var anyPromArr: Promise[]; + +var fooPromArr: Promise[]; +var barPromArr: Promise[]; + +// - - - - - - - - - - - - - - - - - + +var numThenArr: Promise.Thenable[]; +var strThenArr: Promise.Thenable[]; +var anyThenArr: Promise.Thenable[]; + +var fooThenArr: Promise.Thenable[]; +var barThenArr: Promise.Thenable[]; + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +// booya! +var fooThenArrThen: Promise.Thenable[]>; +var barThenArrThen: Promise.Thenable[]>; + +var fooResolver: Promise.Resolver; +var barResolver: Promise.Resolver; + +var fooInspection: Promise.Inspection; +var barInspection: Promise.Inspection; + +var fooInspectionArrProm: Promise[]>; +var barInspectionArrProm: Promise[]>; + +var BlueBird: typeof Promise; + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +fooThen = fooProm; +barThen = barProm; + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +fooProm = new Promise((resolve: (value: Foo) => void, reject: (reason: any) => void) => { + if (bool) { + resolve(foo); + } + else { + reject(new Error(str)); + } +}); +fooProm = new Promise((resolve: (value: Foo) => void) => { + if (bool) { + resolve(foo); + } +}); + +// - - - - - - - - - - - - - - - - - - - - - - - + +// needs a hint when used untyped? +fooProm = new Promise((resolve, reject) => { + if (bool) { + resolve(fooThen); + } + else { + reject(new Error(str)); + } +}); +fooProm = new Promise((resolve) => { + resolve(fooThen); +}); + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +fooResolver.resolve(foo); + +fooResolver.reject(err); + +fooResolver.progress(bar); + +fooResolver.callback = (err: any, value: Foo) => { + +}; + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +bool = fooInspection.isFulfilled(); + +bool = fooInspection.isRejected(); + +bool = fooInspection.isPending(); + +foo = fooInspection.value(); + +x = fooInspection.error(); + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +barProm = fooProm.then((value: Foo) => { + return bar; +}, (reason: any) => { + return bar; +}, (note: any) => { + return bar; +}); +barProm = fooProm.then((value: Foo) => { + return bar; +}, (reason: any) => { + return bar; +}); +barProm = fooProm.then((value: Foo) => { + return bar; +}); + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +barProm = fooProm.catch((reason: any) => { + return bar; +}); +barProm = fooProm.caught((reason: any) => { + return bar; +}); + +barProm = fooProm.catch((reason: any) => { + return bar; +}, (reason: any) => { + return bar; +}); +barProm = fooProm.caught((reason: any) => { + return bar; +}, (reason: any) => { + return bar; +}); + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +barProm = fooProm.catch(Error, (reason: any) => { + return bar; +}); +barProm = fooProm.caught(Error, (reason: any) => { + return bar; +}); + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +barProm = fooProm.error((reason: any) => { + return bar; +}); + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +fooProm = fooProm.finally((value: Foo) => { + // return is ignored + return foo; +}); +fooProm = fooProm.finally((value: Foo) => { + // return is ignored + return fooThen; +}); +fooProm = fooProm.finally((value: Foo) => { + // return is ignored +}); +fooProm = fooProm.finally(() => { + // return is ignored +}); + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +fooProm = fooProm.lastly((value: Foo) => { + // return is ignored + return foo; +}); +fooProm = fooProm.lastly((value: Foo) => { + // return is ignored + return fooThen; +}); +fooProm = fooProm.lastly((value: Foo) => { + // return is ignored +}); +fooProm = fooProm.lastly(() => { + // return is ignored +}); + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +fooProm = fooProm.bind(obj); + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +barProm = fooProm.done((value: Foo) => { + return bar; +}, (reason: any) => { + return bar; +}, (note: any) => { + +}); +barProm = fooProm.done((value: Foo) => { + return bar; +}, (reason: any) => { + return bar; +}); +barProm = fooProm.done((value: Foo) => { + return bar; +}); + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +barProm = fooProm.done((value: Foo) => { + return barThen; +}, (reason: any) => { + return barThen; +}, (note: any) => { + +}); +barProm = fooProm.done((value: Foo) => { + return barThen; +}, (reason: any) => { + return barThen; +}); +barProm = fooProm.done((value: Foo) => { + return barThen; +}); + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +fooProm = fooProm.progressed((note: any) => { + return foo; +}); +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +fooProm = fooProm.delay(num); + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +fooProm = fooProm.timeout(num); +fooProm = fooProm.timeout(num, str); + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +fooProm.nodeify(); +fooProm = fooProm.nodeify((err: any) => { + +}); +fooProm = fooProm.nodeify((err: any, foo?: Foo) => { + +}); + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +barProm = fooProm.fork((value: Foo) => { + return bar; +}, (reason: any) => { + return bar; +}, (note: any) => { + +}); +barProm = fooProm.fork((value: Foo) => { + return bar; +}, (reason: any) => { + return bar; +}); +barProm = fooProm.fork((value: Foo) => { + return bar; +}); + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +barProm = fooProm.fork((value: Foo) => { + return barThen; +}, (reason: any) => { + return barThen; +}, (note: any) => { + +}); +barProm = fooProm.fork((value: Foo) => { + return barThen; +}, (reason: any) => { + return barThen; +}); +barProm = fooProm.fork((value: Foo) => { + return barThen; +}); + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +barProm = fooProm.cancel(); + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +fooProm = fooProm.cancellable(); +fooProm = fooProm.uncancellable(); + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +bool = fooProm.isCancellable(); +bool = fooProm.isFulfilled(); +bool = fooProm.isRejected(); +bool = fooProm.isPending(); +bool = fooProm.isResolved(); + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +fooInspection = fooProm.inspect(); + +anyProm = fooProm.call(str); +anyProm = fooProm.call(str, 1, 2, 3); + +//TODO enable get() test when implemented +// barProm = fooProm.get(str); + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +barProm = fooProm.return(bar); +barProm = fooProm.thenReturn(bar); + +voidProm = fooProm.return(); +voidProm = fooProm.thenReturn(); + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +// fooProm +fooProm = fooProm.throw(err); +fooProm = fooProm.thenThrow(err); + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +str = fooProm.toString(); + +obj = fooProm.toJSON(); + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +barProm = fooArrProm.spread((one: Foo, two: Bar) => { + return bar; +}, (reason: any) => { + return bar; +}); +barProm = fooArrProm.spread((one: Foo, two: Bar, twotwo: Foo) => { + return bar; +}); + +// - - - - - - - - - - - - - - - - - + +barProm = fooArrProm.spread((one: Foo, two: Bar) => { + return barThen; +}, (reason: any) => { + return barThen; +}); +barProm = fooArrProm.spread((one: Foo, two: Bar, twotwo: Foo) => { + return barThen; +}); + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +//TODO fix collection inference + +barArrProm = fooProm.all(); + +objProm = fooProm.props(); + +barInspectionArrProm = fooProm.settle(); + +barProm = fooProm.any(); + +barArrProm = fooProm.some(num); + +barProm = fooProm.race(); + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +//TODO fix collection inference + +barArrProm = fooProm.map((item: Foo, index: number, arrayLength: number) => { + return bar; +}); +barArrProm = fooProm.map((item: Foo) => { + return bar; +}); + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +barProm = fooProm.reduce((memo: Bar, item: Foo, index: number, arrayLength: number) => { + return memo; +}); +barProm = fooProm.reduce((memo: Bar, item: Foo) => { + return memo; +}, bar); + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +fooArrProm = fooArrProm.filter((item: Foo, index: number, arrayLength: number) => { + return bool; +}); +fooArrProm = fooArrProm.filter((item: Foo) => { + return bool; +}); + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + +fooProm = Promise.try(() => { + return foo; +}); +fooProm = Promise.try(() => { + return foo; +}, arr); +fooProm = Promise.try(() => { + return foo; +}, arr, x); + +// - - - - - - - - - - - - - - - - - + +fooProm = Promise.try(() => { + return fooThen; +}); +fooProm = Promise.try(() => { + return fooThen; +}, arr); +fooProm = Promise.try(() => { + return fooThen; +}, arr, x); + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +fooProm = Promise.attempt(() => { + return foo; +}); +fooProm = Promise.attempt(() => { + return foo; +}, arr); +fooProm = Promise.attempt(() => { + return foo; +}, arr, x); + +// - - - - - - - - - - - - - - - - - + +fooProm = Promise.attempt(() => { + return fooThen; +}); +fooProm = Promise.attempt(() => { + return fooThen; +}, arr); +fooProm = Promise.attempt(() => { + return fooThen; +}, arr, x); + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +func = Promise.method(function () { + +}); + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +fooProm = Promise.resolve(foo); +fooProm = Promise.resolve(fooThen); + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +voidProm = Promise.reject(reason); + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +fooResolver = Promise.defer(); + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +fooProm = Promise.cast(foo); +fooProm = Promise.cast(fooThen); + +voidProm = Promise.bind(x); + +bool = Promise.is(value); + +Promise.longStackTraces(); + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +//TODO enable delay + +fooProm = Promise.delay(fooThen, num); +fooProm = Promise.delay(foo, num); +voidProm = Promise.delay(num); + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +func = Promise.promisify(f); +func = Promise.promisify(f, obj); +; + +obj = Promise.promisifyAll(obj); + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +//TODO enable generator +/* + func = Promise.coroutine(f); + + barProm = Promise.spawn(f); + */ +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +BlueBird = Promise.noConflict(); + +Promise.onPossiblyUnhandledRejection((reason: any) => { + +}); + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +//TODO expand tests to overloads +fooArrProm = Promise.all(fooThenArrThen); +fooArrProm = Promise.all(fooArrProm); +fooArrProm = Promise.all(fooThenArr); +fooArrProm = Promise.all(fooArr); + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +objProm = Promise.props(objProm); +objProm = Promise.props(obj); + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +//TODO expand tests to overloads +fooInspectionArrProm = Promise.settle(fooThenArrThen); +fooInspectionArrProm = Promise.settle(fooArrProm); +fooInspectionArrProm = Promise.settle(fooThenArr); +fooInspectionArrProm = Promise.settle(fooArr); + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +//TODO expand tests to overloads +fooProm = Promise.any(fooThenArrThen); +fooProm = Promise.any(fooArrProm); +fooProm = Promise.any(fooThenArr); +fooProm = Promise.any(fooArr); + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +//TODO expand tests to overloads +fooProm = Promise.race(fooThenArrThen); +fooProm = Promise.race(fooArrProm); +fooProm = Promise.race(fooThenArr); +fooProm = Promise.race(fooArr); + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +//TODO expand tests to overloads +fooArrProm = Promise.some(fooThenArrThen, num); +fooArrProm = Promise.some(fooArrThen, num); +fooArrProm = Promise.some(fooThenArr, num); +fooArrProm = Promise.some(fooArr, num); + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +fooArrProm = Promise.join(foo, foo, foo); +fooArrProm = Promise.join(fooThen, fooThen, fooThen); + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +// map() + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +// fooThenArrThen + +barArrProm = Promise.map(fooThenArrThen, (item: Foo) => { + return bar; +}); +barArrProm = Promise.map(fooThenArrThen, (item: Foo) => { + return barThen; +}); +barArrProm = Promise.map(fooThenArrThen, (item: Foo, index: number, arrayLength: number) => { + return bar; +}); +barArrProm = Promise.map(fooThenArrThen, (item: Foo, index: number, arrayLength: number) => { + return barThen; +}); + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +// fooArrThen + +barArrProm = Promise.map(fooArrThen, (item: Foo) => { + return bar; +}); +barArrProm = Promise.map(fooArrThen, (item: Foo) => { + return barThen; +}); +barArrProm = Promise.map(fooArrThen, (item: Foo, index: number, arrayLength: number) => { + return bar; +}); +barArrProm = Promise.map(fooArrThen, (item: Foo, index: number, arrayLength: number) => { + return barThen; +}); + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +// fooThenArr + +barArrProm = Promise.map(fooThenArr, (item: Foo) => { + return bar; +}); +barArrProm = Promise.map(fooThenArr, (item: Foo) => { + return barThen; +}); +barArrProm = Promise.map(fooThenArr, (item: Foo, index: number, arrayLength: number) => { + return bar; +}); +barArrProm = Promise.map(fooThenArr, (item: Foo, index: number, arrayLength: number) => { + return barThen; +}); + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +// fooArr + +barArrProm = Promise.map(fooArr, (item: Foo) => { + return bar; +}); +barArrProm = Promise.map(fooArr, (item: Foo) => { + return barThen; +}); +barArrProm = Promise.map(fooArr, (item: Foo, index: number, arrayLength: number) => { + return bar; +}); +barArrProm = Promise.map(fooArr, (item: Foo, index: number, arrayLength: number) => { + return barThen; +}); + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +// reduce() + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +// fooThenArrThen + +barProm = Promise.reduce(fooThenArrThen, (memo: Bar, item: Foo) => { + return memo; +}, bar); +barProm = Promise.reduce(fooThenArrThen, (memo: Bar, item: Foo) => { + return barThen; +}, bar); +barProm = Promise.reduce(fooThenArrThen, (memo: Bar, item: Foo, index: number, arrayLength: number) => { + return memo; +}, bar); +barProm = Promise.reduce(fooThenArrThen, (memo: Bar, item: Foo, index: number, arrayLength: number) => { + return barThen; +}, bar); + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +// fooArrThen + +barProm = Promise.reduce(fooArrThen, (memo: Bar, item: Foo) => { + return memo; +}, bar); +barProm = Promise.reduce(fooArrThen, (memo: Bar, item: Foo) => { + return barThen; +}, bar); +barProm = Promise.reduce(fooArrThen, (memo: Bar, item: Foo, index: number, arrayLength: number) => { + return memo; +}, bar); +barProm = Promise.reduce(fooArrThen, (memo: Bar, item: Foo, index: number, arrayLength: number) => { + return barThen; +}, bar); + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +// fooThenArr + +barProm = Promise.reduce(fooThenArr, (memo: Bar, item: Foo) => { + return memo; +}, bar); +barProm = Promise.reduce(fooThenArr, (memo: Bar, item: Foo) => { + return barThen; +}, bar); +barProm = Promise.reduce(fooThenArr, (memo: Bar, item: Foo, index: number, arrayLength: number) => { + return memo; +}, bar); +barProm = Promise.reduce(fooThenArr, (memo: Bar, item: Foo, index: number, arrayLength: number) => { + return barThen; +}, bar); + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +// fooArr + +barProm = Promise.reduce(fooArr, (memo: Bar, item: Foo) => { + return memo; +}, bar); +barProm = Promise.reduce(fooArr, (memo: Bar, item: Foo) => { + return barThen; +}, bar); +barProm = Promise.reduce(fooArr, (memo: Bar, item: Foo, index: number, arrayLength: number) => { + return memo; +}, bar); +barProm = Promise.reduce(fooArr, (memo: Bar, item: Foo, index: number, arrayLength: number) => { + return barThen; +}, bar); + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +// filter() + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +// fooThenArrThen + +fooArrProm = Promise.filter(fooThenArrThen, (item: Foo) => { + return bool; +}); +fooArrProm = Promise.filter(fooThenArrThen, (item: Foo) => { + return boolThen; +}); +fooArrProm = Promise.filter(fooThenArrThen, (item: Foo, index: number, arrayLength: number) => { + return bool; +}); +fooArrProm = Promise.filter(fooThenArrThen, (item: Foo, index: number, arrayLength: number) => { + return boolThen; +}); + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +// fooArrThen + +fooArrProm = Promise.filter(fooArrThen, (item: Foo) => { + return bool; +}); +fooArrProm = Promise.filter(fooArrThen, (item: Foo) => { + return boolThen; +}); +fooArrProm = Promise.filter(fooArrThen, (item: Foo, index: number, arrayLength: number) => { + return bool; +}); +fooArrProm = Promise.filter(fooArrThen, (item: Foo, index: number, arrayLength: number) => { + return boolThen; +}); + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +// fooThenArr + +fooArrProm = Promise.filter(fooThenArr, (item: Foo) => { + return bool; +}); +fooArrProm = Promise.filter(fooThenArr, (item: Foo) => { + return boolThen; +}); +fooArrProm = Promise.filter(fooThenArr, (item: Foo, index: number, arrayLength: number) => { + return bool; +}); +fooArrProm = Promise.filter(fooThenArr, (item: Foo, index: number, arrayLength: number) => { + return boolThen; +}); + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +// fooArr + +fooArrProm = Promise.filter(fooArr, (item: Foo) => { + return bool; +}); +fooArrProm = Promise.filter(fooArr, (item: Foo) => { + return boolThen; +}); +fooArrProm = Promise.filter(fooArr, (item: Foo, index: number, arrayLength: number) => { + return bool; +}); +fooArrProm = Promise.filter(fooArr, (item: Foo, index: number, arrayLength: number) => { + return boolThen; +}); + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/bluebird/bluebird-1.0.d.ts b/bluebird/bluebird-1.0.d.ts new file mode 100644 index 0000000000..210032f864 --- /dev/null +++ b/bluebird/bluebird-1.0.d.ts @@ -0,0 +1,670 @@ +// Type definitions for bluebird 1.0.0 +// Project: https://github.com/petkaantonov/bluebird +// Definitions by: Bart van der Schoor +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +// ES6 model with generics overload was sourced and trans-multiplied from es6-promises.d.ts +// By: Campredon + +// Warning: recommended to use `tsc > v0.9.7` (critical bugs in earlier generic code): +// - https://github.com/borisyankov/DefinitelyTyped/issues/1563 + +// Note: replicate changes to all overloads in both definition and test file +// Note: keep both static and instance members inline (so similar) + +// TODO fix remaining TODO annotations in both definition and test + +// TODO verify support to have no return statement in handlers to get a Promise (more overloads?) + +declare class Promise implements Promise.Thenable { + /** + * Create a new promise. The passed in function will receive functions `resolve` and `reject` as its arguments which can be called to seal the fate of the created promise. + */ + constructor(callback: (resolve: (thenable: Promise.Thenable) => void, reject: (error: any) => void) => void); + constructor(callback: (resolve: (result: R) => void, reject: (error: any) => void) => void); + + /** + * Promises/A+ `.then()` with progress handler. Returns a new promise chained from this promise. The new promise will be rejected or resolved dedefer on the passed `fulfilledHandler`, `rejectedHandler` and the state of this promise. + */ + then(onFulfill: (value: R) => Promise.Thenable, onReject: (error: any) => Promise.Thenable, onProgress?: (note: any) => any): Promise; + then(onFulfill: (value: R) => Promise.Thenable, onReject?: (error: any) => U, onProgress?: (note: any) => any): Promise; + then(onFulfill: (value: R) => U, onReject: (error: any) => Promise.Thenable, onProgress?: (note: any) => any): Promise; + then(onFulfill?: (value: R) => U, onReject?: (error: any) => U, onProgress?: (note: any) => any): Promise; + + /** + * This is a catch-all exception handler, shortcut for calling `.then(null, handler)` on this promise. Any exception happening in a `.then`-chain will propagate to nearest `.catch` handler. + * + * Alias `.caught();` for compatibility with earlier ECMAScript version. + */ + catch(onReject?: (error: any) => Promise.Thenable): Promise; + caught(onReject?: (error: any) => Promise.Thenable): Promise; + + catch(onReject?: (error: any) => U): Promise; + caught(onReject?: (error: any) => U): Promise; + + /** + * This extends `.catch` to work more like catch-clauses in languages like Java or C#. Instead of manually checking `instanceof` or `.name === "SomeError"`, you may specify a number of error constructors which are eligible for this catch handler. The catch handler that is first met that has eligible constructors specified, is the one that will be called. + * + * This method also supports predicate-based filters. If you pass a predicate function instead of an error constructor, the predicate will receive the error as an argument. The return result of the predicate will be used determine whether the error handler should be called. + * + * Alias `.caught();` for compatibility with earlier ECMAScript version. + */ + catch(predicate: (error: any) => boolean, onReject: (error: any) => Promise.Thenable): Promise; + caught(predicate: (error: any) => boolean, onReject: (error: any) => Promise.Thenable): Promise; + + catch(predicate: (error: any) => boolean, onReject: (error: any) => U): Promise; + caught(predicate: (error: any) => boolean, onReject: (error: any) => U): Promise; + + catch(ErrorClass: Function, onReject: (error: any) => Promise.Thenable): Promise; + caught(ErrorClass: Function, onReject: (error: any) => Promise.Thenable): Promise; + + catch(ErrorClass: Function, onReject: (error: any) => U): Promise; + caught(ErrorClass: Function, onReject: (error: any) => U): Promise; + + /** + * Like `.catch` but instead of catching all types of exceptions, it only catches those that don't originate from thrown errors but rather from explicit rejections. + */ + error(onReject: (reason: any) => Promise.Thenable): Promise; + error(onReject: (reason: any) => U): Promise; + + /** + * Pass a handler that will be called regardless of this promise's fate. Returns a new promise chained from this promise. There are special semantics for `.finally()` in that the final value cannot be modified from the handler. + * + * Alias `.lastly();` for compatibility with earlier ECMAScript version. + */ + finally(handler: (value: R) => Promise.Thenable): Promise; + finally(handler: (value: R) => R): Promise; + finally(handler: (value: R) => void): Promise; + + lastly(handler: (value: R) => Promise.Thenable): Promise; + lastly(handler: (value: R) => R): Promise; + lastly(handler: (value: R) => void): Promise; + + /** + * Create a promise that follows this promise, but is bound to the given `thisArg` value. A bound promise will call its handlers with the bound value set to `this`. Additionally promises derived from a bound promise will also be bound promises with the same `thisArg` binding as the original promise. + */ + bind(thisArg: any): Promise; + + /** + * Like `.then()`, but any unhandled rejection that ends up here will be thrown as an error. + */ + done(onFulfilled: (value: R) => Promise.Thenable, onRejected: (error: any) => Promise.Thenable, onProgress?: (note: any) => any): Promise; + done(onFulfilled: (value: R) => Promise.Thenable, onRejected?: (error: any) => U, onProgress?: (note: any) => any): Promise; + done(onFulfilled: (value: R) => U, onRejected: (error: any) => Promise.Thenable, onProgress?: (note: any) => any): Promise; + done(onFulfilled?: (value: R) => U, onRejected?: (error: any) => U, onProgress?: (note: any) => any): Promise; + + /** + * Shorthand for `.then(null, null, handler);`. Attach a progress handler that will be called if this promise is progressed. Returns a new promise chained from this promise. + */ + progressed(handler: (note: any) => any): Promise; + + /** + * Same as calling `Promise.delay(this, ms)`. With the exception that if this promise is bound to a value, the returned promise is bound to that value too. + */ + delay(ms: number): Promise; + + /** + * Returns a promise that will be fulfilled with this promise's fulfillment value or rejection reason. However, if this promise is not fulfilled or rejected within `ms` milliseconds, the returned promise is rejected with a `Promise.TimeoutError` instance. + * + * You may specify a custom error message with the `message` parameter. + */ + timeout(ms: number, message?: string): Promise; + + /** + * Register a node-style callback on this promise. When this promise is is either fulfilled or rejected, the node callback will be called back with the node.js convention where error reason is the first argument and success value is the second argument. The error argument will be `null` in case of success. + * Returns back this promise instead of creating a new one. If the `callback` argument is not a function, this method does not do anything. + */ + nodeify(callback: (err: any, value?: R) => void): Promise; + nodeify(...sink: any[]): void; + + /** + * Marks this promise as cancellable. Promises by default are not cancellable after v0.11 and must be marked as such for `.cancel()` to have any effect. Marking a promise as cancellable is infectious and you don't need to remark any descendant promise. + */ + cancellable(): Promise; + + /** + * Cancel this promise. The cancellation will propagate to farthest cancellable ancestor promise which is still pending. + * + * That ancestor will then be rejected with a `CancellationError` (get a reference from `Promise.CancellationError`) object as the rejection reason. + * + * In a promise rejection handler you may check for a cancellation by seeing if the reason object has `.name === "Cancel"`. + * + * Promises are by default not cancellable. Use `.cancellable()` to mark a promise as cancellable. + */ + // TODO what to do with this? + cancel(): Promise; + + /** + * Like `.then()`, but cancellation of the the returned promise or any of its descendant will not propagate cancellation to this promise or this promise's ancestors. + */ + fork(onFulfilled: (value: R) => Promise.Thenable, onRejected: (error: any) => Promise.Thenable, onProgress?: (note: any) => any): Promise; + fork(onFulfilled: (value: R) => Promise.Thenable, onRejected?: (error: any) => U, onProgress?: (note: any) => any): Promise; + fork(onFulfilled: (value: R) => U, onRejected: (error: any) => Promise.Thenable, onProgress?: (note: any) => any): Promise; + fork(onFulfilled?: (value: R) => U, onRejected?: (error: any) => U, onProgress?: (note: any) => any): Promise; + + /** + * Create an uncancellable promise based on this promise. + */ + uncancellable(): Promise; + + /** + * See if this promise can be cancelled. + */ + isCancellable(): boolean; + + /** + * See if this `promise` has been fulfilled. + */ + isFulfilled(): boolean; + + /** + * See if this `promise` has been rejected. + */ + isRejected(): boolean; + + /** + * See if this `promise` is still defer. + */ + isPending(): boolean; + + /** + * See if this `promise` is resolved -> either fulfilled or rejected. + */ + isResolved(): boolean; + + /** + * Synchronously inspect the state of this `promise`. The `PromiseInspection` will represent the state of the promise as snapshotted at the time of calling `.inspect()`. + */ + inspect(): Promise.Inspection; + + /** + * This is a convenience method for doing: + * + * + * promise.then(function(obj){ + * return obj[propertyName].call(obj, arg...); + * }); + * + */ + call(propertyName: string, ...args: any[]): Promise; + + /** + * This is a convenience method for doing: + * + * + * promise.then(function(obj){ + * return obj[propertyName]; + * }); + * + */ + // TODO find way to fix get() + // get(propertyName: string): Promise; + + /** + * Convenience method for: + * + * + * .then(function() { + * return value; + * }); + * + * + * in the case where `value` doesn't change its value. That means `value` is bound at the time of calling `.return()` + * + * Alias `.thenReturn();` for compatibility with earlier ECMAScript version. + */ + return(): Promise; + thenReturn(): Promise; + return(value: U): Promise; + thenReturn(value: U): Promise; + + /** + * Convenience method for: + * + * + * .then(function() { + * throw reason; + * }); + * + * Same limitations apply as with `.return()`. + * + * Alias `.thenThrow();` for compatibility with earlier ECMAScript version. + */ + throw(reason: Error): Promise; + thenThrow(reason: Error): Promise; + + /** + * Convert to String. + */ + toString(): string; + + /** + * This is implicitly called by `JSON.stringify` when serializing the object. Returns a serialized representation of the `Promise`. + */ + toJSON(): Object; + + /** + * Like calling `.then`, but the fulfillment value or rejection reason is assumed to be an array, which is flattened to the formal parameters of the handlers. + */ + // TODO how to model instance.spread()? like Q? + spread(onFulfill: Function, onReject?: (reason: any) => Promise.Thenable): Promise; + spread(onFulfill: Function, onReject?: (reason: any) => U): Promise; + /* + // TODO or something like this? + spread(onFulfill: (...values: W[]) => Promise.Thenable, onReject?: (reason: any) => Promise.Thenable): Promise; + spread(onFulfill: (...values: W[]) => Promise.Thenable, onReject?: (reason: any) => U): Promise; + spread(onFulfill: (...values: W[]) => U, onReject?: (reason: any) => Promise.Thenable): Promise; + spread(onFulfill: (...values: W[]) => U, onReject?: (reason: any) => U): Promise; + */ + /** + * Same as calling `Promise.all(thisPromise)`. With the exception that if this promise is bound to a value, the returned promise is bound to that value too. + */ + // TODO type inference from array-resolving promise? + all(): Promise; + + /** + * Same as calling `Promise.props(thisPromise)`. With the exception that if this promise is bound to a value, the returned promise is bound to that value too. + */ + // TODO how to model instance.props()? + props(): Promise; + + /** + * Same as calling `Promise.settle(thisPromise)`. With the exception that if this promise is bound to a value, the returned promise is bound to that value too. + */ + // TODO type inference from array-resolving promise? + settle(): Promise[]>; + + /** + * Same as calling `Promise.any(thisPromise)`. With the exception that if this promise is bound to a value, the returned promise is bound to that value too. + */ + // TODO type inference from array-resolving promise? + any(): Promise; + + /** + * Same as calling `Promise.some(thisPromise)`. With the exception that if this promise is bound to a value, the returned promise is bound to that value too. + */ + // TODO type inference from array-resolving promise? + some(count: number): Promise; + + /** + * Same as calling `Promise.race(thisPromise, count)`. With the exception that if this promise is bound to a value, the returned promise is bound to that value too. + */ + // TODO type inference from array-resolving promise? + race(): Promise; + + /** + * Same as calling `Promise.map(thisPromise, mapper)`. With the exception that if this promise is bound to a value, the returned promise is bound to that value too. + */ + // TODO type inference from array-resolving promise? + map(mapper: (item: Q, index: number, arrayLength: number) => Promise.Thenable): Promise; + map(mapper: (item: Q, index: number, arrayLength: number) => U): Promise; + + /** + * Same as calling `Promise.reduce(thisPromise, Function reducer, initialValue)`. With the exception that if this promise is bound to a value, the returned promise is bound to that value too. + */ + // TODO type inference from array-resolving promise? + reduce(reducer: (memo: U, item: Q, index: number, arrayLength: number) => Promise.Thenable, initialValue?: U): Promise; + reduce(reducer: (memo: U, item: Q, index: number, arrayLength: number) => U, initialValue?: U): Promise; + + /** + * Same as calling ``Promise.filter(thisPromise, filterer)``. With the exception that if this promise is bound to a value, the returned promise is bound to that value too. + */ + // TODO type inference from array-resolving promise? + filter(filterer: (item: U, index: number, arrayLength: number) => Promise.Thenable): Promise; + filter(filterer: (item: U, index: number, arrayLength: number) => boolean): Promise; + + /** + * Start the chain of promises with `Promise.try`. Any synchronous exceptions will be turned into rejections on the returned promise. + * + * Note about second argument: if it's specifically a true array, its values become respective arguments for the function call. Otherwise it is passed as is as the first argument for the function call. + * + * Alias for `attempt();` for compatibility with earlier ECMAScript version. + */ + static try(fn: () => Promise.Thenable, args?: any[], ctx?: any): Promise; + static try(fn: () => R, args?: any[], ctx?: any): Promise; + + static attempt(fn: () => Promise.Thenable, args?: any[], ctx?: any): Promise; + static attempt(fn: () => R, args?: any[], ctx?: any): Promise; + + /** + * Returns a new function that wraps the given function `fn`. The new function will always return a promise that is fulfilled with the original functions return values or rejected with thrown exceptions from the original function. + * This method is convenient when a function can sometimes return synchronously or throw synchronously. + */ + static method(fn: Function): Function; + + /** + * Create a promise that is resolved with the given `value`. If `value` is a thenable or promise, the returned promise will assume its state. + */ + static resolve(): Promise; + static resolve(value: Promise.Thenable): Promise; + static resolve(value: R): Promise; + + /** + * Create a promise that is rejected with the given `reason`. + */ + static reject(reason: any): Promise; + static reject(reason: any): Promise; + + /** + * Create a promise with undecided fate and return a `PromiseResolver` to control it. See resolution?: Promise(#promise-resolution). + */ + static defer(): Promise.Resolver; + + /** + * Cast the given `value` to a trusted promise. If `value` is already a trusted `Promise`, it is returned as is. If `value` is not a thenable, a fulfilled is: Promise returned with `value` as its fulfillment value. If `value` is a thenable (Promise-like object, like those returned by jQuery's `$.ajax`), returns a trusted that: Promise assimilates the state of the thenable. + */ + static cast(value: Promise.Thenable): Promise; + static cast(value: R): Promise; + + /** + * Sugar for `Promise.resolve(undefined).bind(thisArg);`. See `.bind()`. + */ + static bind(thisArg: any): Promise; + + /** + * See if `value` is a trusted Promise. + */ + static is(value: any): boolean; + + /** + * Call this right after the library is loaded to enabled long stack traces. Long stack traces cannot be disabled after being enabled, and cannot be enabled after promises have alread been created. Long stack traces imply a substantial performance penalty, around 4-5x for throughput and 0.5x for latency. + */ + static longStackTraces(): void; + + /** + * Returns a promise that will be fulfilled with `value` (or `undefined`) after given `ms` milliseconds. If `value` is a promise, the delay will start counting down when it is fulfilled and the returned promise will be fulfilled with the fulfillment value of the `value` promise. + */ + // TODO enable more overloads + static delay(value: Promise.Thenable, ms: number): Promise; + static delay(value: R, ms: number): Promise; + static delay(ms: number): Promise; + + /** + * Returns a function that will wrap the given `nodeFunction`. Instead of taking a callback, the returned function will return a promise whose fate is decided by the callback behavior of the given node function. The node function should conform to node.js convention of accepting a callback as last argument and calling that callback with error as the first argument and success value on the second argument. + * + * If the `nodeFunction` calls its callback with multiple success values, the fulfillment value will be an array of them. + * + * If you pass a `receiver`, the `nodeFunction` will be called as a method on the `receiver`. + */ + // TODO how to model promisify? + static promisify(nodeFunction: Function, receiver?: any): Function; + + /** + * Promisifies the entire object by going through the object's properties and creating an async equivalent of each function on the object and its prototype chain. The promisified method name will be the original method name postfixed with `Async`. Returns the input object. + * + * Note that the original methods on the object are not overwritten but new methods are created with the `Async`-postfix. For example, if you `promisifyAll()` the node.js `fs` object use `fs.statAsync()` to call the promisified `stat` method. + */ + // TODO how to model promisifyAll? + static promisifyAll(target: Object): Object; + + /** + * Returns a function that can use `yield` to run asynchronous code synchronously. This feature requires the support of generators which are drafted in the next version of the language. Node version greater than `0.11.2` is required and needs to be executed with the `--harmony-generators` (or `--harmony`) command-line switch. + */ + // TODO fix coroutine GeneratorFunction + static coroutine(generatorFunction: Function): Function; + + /** + * Spawn a coroutine which may yield promises to run asynchronous code synchronously. This feature requires the support of generators which are drafted in the next version of the language. Node version greater than `0.11.2` is required and needs to be executed with the `--harmony-generators` (or `--harmony`) command-line switch. + */ + // TODO fix spawn GeneratorFunction + static spawn(generatorFunction: Function): Promise; + + /** + * This is relevant to browser environments with no module loader. + * + * Release control of the `Promise` namespace to whatever it was before this library was loaded. Returns a reference to the library namespace so you can attach it to something else. + */ + static noConflict(): typeof Promise; + + /** + * Add `handler` as the handler to call when there is a possibly unhandled rejection. The default handler logs the error stack to stderr or `console.error` in browsers. + * + * Passing no value or a non-function will have the effect of removing any kind of handling for possibly unhandled rejections. + */ + static onPossiblyUnhandledRejection(handler: (reason: any) => any): void; + + /** + * Given an array, or a promise of an array, which contains promises (or a mix of promises and values) return a promise that is fulfilled when all the items in the array are fulfilled. The promise's fulfillment value is an array with fulfillment values at respective positions to the original array. If any promise in the array rejects, the returned promise is rejected with the rejection reason. + */ + // TODO enable more overloads + // promise of array with promises of value + static all(values: Promise.Thenable[]>): Promise; + // promise of array with values + static all(values: Promise.Thenable): Promise; + // array with promises of value + static all(values: Promise.Thenable[]): Promise; + // array with values + static all(values: R[]): Promise; + + /** + * Like ``Promise.all`` but for object properties instead of array items. Returns a promise that is fulfilled when all the properties of the object are fulfilled. The promise's fulfillment value is an object with fulfillment values at respective keys to the original object. If any promise in the object rejects, the returned promise is rejected with the rejection reason. + * + * If `object` is a trusted `Promise`, then it will be treated as a promise for object rather than for its properties. All other objects are treated for their properties as is returned by `Object.keys` - the object's own enumerable properties. + * + * *The original object is not modified.* + */ + // TODO verify this is correct + // trusted promise for object + static props(object: Promise): Promise; + // object + static props(object: Object): Promise; + + /** + * Given an array, or a promise of an array, which contains promises (or a mix of promises and values) return a promise that is fulfilled when all the items in the array are either fulfilled or rejected. The fulfillment value is an array of ``PromiseInspection`` instances at respective positions in relation to the input array. + * + * *original: The array is not modified. The input array sparsity is retained in the resulting array.* + */ + // promise of array with promises of value + static settle(values: Promise.Thenable[]>): Promise[]>; + // promise of array with values + static settle(values: Promise.Thenable): Promise[]>; + // array with promises of value + static settle(values: Promise.Thenable[]): Promise[]>; + // array with values + static settle(values: R[]): Promise[]>; + + /** + * Like `Promise.some()`, with 1 as `count`. However, if the promise fulfills, the fulfillment value is not an array of 1 but the value directly. + */ + // promise of array with promises of value + static any(values: Promise.Thenable[]>): Promise; + // promise of array with values + static any(values: Promise.Thenable): Promise; + // array with promises of value + static any(values: Promise.Thenable[]): Promise; + // array with values + static any(values: R[]): Promise; + + /** + * Given an array, or a promise of an array, which contains promises (or a mix of promises and values) return a promise that is fulfilled or rejected as soon as a promise in the array is fulfilled or rejected with the respective rejection reason or fulfillment value. + * + * **Note** If you pass empty array or a sparse array with no values, or a promise/thenable for such, it will be forever pending. + */ + // promise of array with promises of value + static race(values: Promise.Thenable[]>): Promise; + // promise of array with values + static race(values: Promise.Thenable): Promise; + // array with promises of value + static race(values: Promise.Thenable[]): Promise; + // array with values + static race(values: R[]): Promise; + + /** + * Initiate a competetive race between multiple promises or values (values will become immediately fulfilled promises). When `count` amount of promises have been fulfilled, the returned promise is fulfilled with an array that contains the fulfillment values of the winners in order of resolution. + * + * If too many promises are rejected so that the promise can never become fulfilled, it will be immediately rejected with an array of rejection reasons in the order they were thrown in. + * + * *The original array is not modified.* + */ + // promise of array with promises of value + static some(values: Promise.Thenable[]>, count: number): Promise; + // promise of array with values + static some(values: Promise.Thenable, count: number): Promise; + // array with promises of value + static some(values: Promise.Thenable[], count: number): Promise; + // array with values + static some(values: R[], count: number): Promise; + + /** + * Like `Promise.all()` but instead of having to pass an array, the array is generated from the passed variadic arguments. + */ + // variadic array with promises of value + static join(...values: Promise.Thenable[]): Promise; + // variadic array with values + static join(...values: R[]): Promise; + + /** + * Map an array, or a promise of an array, which contains a promises (or a mix of promises and values) with the given `mapper` function with the signature `(item, index, arrayLength)` where `item` is the resolved value of a respective promise in the input array. If any promise in the input array is rejected the returned promise is rejected as well. + * + * If the `mapper` function returns promises or thenables, the returned promise will wait for all the mapped results to be resolved as well. + * + * *The original array is not modified.* + */ + // promise of array with promises of value + static map(values: Promise.Thenable[]>, mapper: (item: R, index: number, arrayLength: number) => Promise.Thenable): Promise; + static map(values: Promise.Thenable[]>, mapper: (item: R, index: number, arrayLength: number) => U): Promise; + + // promise of array with values + static map(values: Promise.Thenable, mapper: (item: R, index: number, arrayLength: number) => Promise.Thenable): Promise; + static map(values: Promise.Thenable, mapper: (item: R, index: number, arrayLength: number) => U): Promise; + + // array with promises of value + static map(values: Promise.Thenable[], mapper: (item: R, index: number, arrayLength: number) => Promise.Thenable): Promise; + static map(values: Promise.Thenable[], mapper: (item: R, index: number, arrayLength: number) => U): Promise; + + // array with values + static map(values: R[], mapper: (item: R, index: number, arrayLength: number) => Promise.Thenable): Promise; + static map(values: R[], mapper: (item: R, index: number, arrayLength: number) => U): Promise; + + /** + * Reduce an array, or a promise of an array, which contains a promises (or a mix of promises and values) with the given `reducer` function with the signature `(total, current, index, arrayLength)` where `item` is the resolved value of a respective promise in the input array. If any promise in the input array is rejected the returned promise is rejected as well. + * + * If the reducer function returns a promise or a thenable, the result for the promise is awaited for before continuing with next iteration. + * + * *The original array is not modified. If no `intialValue` is given and the array doesn't contain at least 2 items, the callback will not be called and `undefined` is returned. If `initialValue` is given and the array doesn't have at least 1 item, `initialValue` is returned.* + */ + // promise of array with promises of value + static reduce(values: Promise.Thenable[]>, reducer: (total: U, current: R, index: number, arrayLength: number) => Promise.Thenable, initialValue?: U): Promise; + static reduce(values: Promise.Thenable[]>, reducer: (total: U, current: R, index: number, arrayLength: number) => U, initialValue?: U): Promise; + + // promise of array with values + static reduce(values: Promise.Thenable, reducer: (total: U, current: R, index: number, arrayLength: number) => Promise.Thenable, initialValue?: U): Promise; + static reduce(values: Promise.Thenable, reducer: (total: U, current: R, index: number, arrayLength: number) => U, initialValue?: U): Promise; + + // array with promises of value + static reduce(values: Promise.Thenable[], reducer: (total: U, current: R, index: number, arrayLength: number) => Promise.Thenable, initialValue?: U): Promise; + static reduce(values: Promise.Thenable[], reducer: (total: U, current: R, index: number, arrayLength: number) => U, initialValue?: U): Promise; + + // array with values + static reduce(values: R[], reducer: (total: U, current: R, index: number, arrayLength: number) => Promise.Thenable, initialValue?: U): Promise; + static reduce(values: R[], reducer: (total: U, current: R, index: number, arrayLength: number) => U, initialValue?: U): Promise; + + /** + * Filter an array, or a promise of an array, which contains a promises (or a mix of promises and values) with the given `filterer` function with the signature `(item, index, arrayLength)` where `item` is the resolved value of a respective promise in the input array. If any promise in the input array is rejected the returned promise is rejected as well. + * + * The return values from the filtered functions are coerced to booleans, with the exception of promises and thenables which are awaited for their eventual result. + * + * *The original array is not modified. + */ + // promise of array with promises of value + static filter(values: Promise.Thenable[]>, filterer: (item: R, index: number, arrayLength: number) => Promise.Thenable): Promise; + static filter(values: Promise.Thenable[]>, filterer: (item: R, index: number, arrayLength: number) => boolean): Promise; + + // promise of array with values + static filter(values: Promise.Thenable, filterer: (item: R, index: number, arrayLength: number) => Promise.Thenable): Promise; + static filter(values: Promise.Thenable, filterer: (item: R, index: number, arrayLength: number) => boolean): Promise; + + // array with promises of value + static filter(values: Promise.Thenable[], filterer: (item: R, index: number, arrayLength: number) => Promise.Thenable): Promise; + static filter(values: Promise.Thenable[], filterer: (item: R, index: number, arrayLength: number) => boolean): Promise; + + // array with values + static filter(values: R[], filterer: (item: R, index: number, arrayLength: number) => Promise.Thenable): Promise; + static filter(values: R[], filterer: (item: R, index: number, arrayLength: number) => boolean): Promise; +} + +declare module Promise { + export interface RangeError extends Error { + } + export interface CancellationError extends Error { + } + export interface TimeoutError extends Error { + } + export interface TypeError extends Error { + } + export interface RejectionError extends Error { + } + + export interface Thenable { + then(onFulfilled: (value: R) => Thenable, onRejected: (error: any) => Thenable): Thenable; + then(onFulfilled: (value: R) => Thenable, onRejected?: (error: any) => U): Thenable; + then(onFulfilled: (value: R) => U, onRejected: (error: any) => Thenable): Thenable; + then(onFulfilled?: (value: R) => U, onRejected?: (error: any) => U): Thenable; + } + + export interface Resolver { + /** + * Returns a reference to the controlled promise that can be passed to clients. + */ + promise: Promise; + + /** + * Resolve the underlying promise with `value` as the resolution value. If `value` is a thenable or a promise, the underlying promise will assume its state. + */ + resolve(value: R): void; + resolve(): void; + + /** + * Reject the underlying promise with `reason` as the rejection reason. + */ + reject(reason: any): void; + + /** + * Progress the underlying promise with `value` as the progression value. + */ + progress(value: any): void; + + /** + * Gives you a callback representation of the `PromiseResolver`. Note that this is not a method but a property. The callback accepts error object in first argument and success values on the 2nd parameter and the rest, I.E. node js conventions. + * + * If the the callback is called with multiple success values, the resolver fullfills its promise with an array of the values. + */ + // TODO specify resolver callback + callback: (err: any, value: R, ...values: R[]) => void; + } + + export interface Inspection { + /** + * See if the underlying promise was fulfilled at the creation time of this inspection object. + */ + isFulfilled(): boolean; + + /** + * See if the underlying promise was rejected at the creation time of this inspection object. + */ + isRejected(): boolean; + + /** + * See if the underlying promise was defer at the creation time of this inspection object. + */ + isPending(): boolean; + + /** + * Get the fulfillment value of the underlying promise. Throws if the promise wasn't fulfilled at the creation time of this inspection object. + * + * throws `TypeError` + */ + value(): R; + + /** + * Get the rejection reason for the underlying promise. Throws if the promise wasn't rejected at the creation time of this inspection object. + * + * throws `TypeError` + */ + error(): any; + } +} + +declare module 'bluebird' { + export = Promise; +} diff --git a/bluebird/bluebird-tests.ts b/bluebird/bluebird-tests.ts index 6eb154e83d..65d9a0055d 100644 --- a/bluebird/bluebird-tests.ts +++ b/bluebird/bluebird-tests.ts @@ -20,6 +20,7 @@ var exp: RegExp; var anyArr: any[]; var strArr: string[]; var numArr: number[]; +var voidVar: void; // - - - - - - - - - - - - - - - - - @@ -199,7 +200,7 @@ bool = fooInspection.isPending(); foo = fooInspection.value(); -x = fooInspection.error(); +x = fooInspection.reason(); // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -244,9 +245,15 @@ barProm = fooProm.caught((reason: any) => { barProm = fooProm.catch(Error, (reason: any) => { return bar; }); +barProm = fooProm.catch(Promise.CancellationError, (reason: any) => { + return bar; +}); barProm = fooProm.caught(Error, (reason: any) => { return bar; }); +barProm = fooProm.caught(Promise.CancellationError, (reason: any) => { + return bar; +}); // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -256,36 +263,28 @@ barProm = fooProm.error((reason: any) => { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -fooProm = fooProm.finally((value: Foo) => { - // return is ignored - return foo; -}); -fooProm = fooProm.finally((value: Foo) => { - // return is ignored - return fooThen; -}); -fooProm = fooProm.finally((value: Foo) => { - // return is ignored +fooProm = fooProm.finally(() => { + // non-Thenable return is ignored + return "foo"; }); fooProm = fooProm.finally(() => { - // return is ignored + return fooThen; +}); +fooProm = fooProm.finally(() => { + // non-Thenable return is ignored }); // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -fooProm = fooProm.lastly((value: Foo) => { - // return is ignored - return foo; -}); -fooProm = fooProm.lastly((value: Foo) => { - // return is ignored - return fooThen; -}); -fooProm = fooProm.lastly((value: Foo) => { - // return is ignored +fooProm = fooProm.lastly(() => { + // non-Thenable return is ignored + return "foo"; }); fooProm = fooProm.lastly(() => { - // return is ignored + return fooThen; +}); +fooProm = fooProm.lastly(() => { + // non-Thenable return is ignored }); // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -294,40 +293,56 @@ fooProm = fooProm.bind(obj); // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -barProm = fooProm.done((value: Foo) => { +voidVar = fooProm.done((value: Foo) => { return bar; }, (reason: any) => { return bar; }, (note: any) => { }); -barProm = fooProm.done((value: Foo) => { +voidVar = fooProm.done((value: Foo) => { return bar; }, (reason: any) => { return bar; }); -barProm = fooProm.done((value: Foo) => { +voidVar = fooProm.done((value: Foo) => { return bar; }); // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -barProm = fooProm.done((value: Foo) => { +voidVar = fooProm.done((value: Foo) => { return barThen; }, (reason: any) => { return barThen; }, (note: any) => { }); -barProm = fooProm.done((value: Foo) => { +voidVar = fooProm.done((value: Foo) => { return barThen; }, (reason: any) => { return barThen; }); -barProm = fooProm.done((value: Foo) => { +voidVar = fooProm.done((value: Foo) => { return barThen; }); +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +fooProm = fooProm.tap((value: Foo) => { + // non-Thenable return is ignored + return "foo"; +}); +fooProm = fooProm.tap((value: Foo) => { + return fooThen; +}); +fooProm = fooProm.tap((value: Foo) => { + return voidThen; +}); +fooProm = fooProm.tap(() => { + // non-Thenable return is ignored +}); + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - fooProm = fooProm.progressed((note: any) => { diff --git a/bluebird/bluebird.d.ts b/bluebird/bluebird.d.ts index 210032f864..f9f081c963 100644 --- a/bluebird/bluebird.d.ts +++ b/bluebird/bluebird.d.ts @@ -16,7 +16,7 @@ // TODO verify support to have no return statement in handlers to get a Promise (more overloads?) -declare class Promise implements Promise.Thenable { +declare class Promise implements Promise.Thenable, Promise.Inspection { /** * Create a new promise. The passed in function will receive functions `resolve` and `reject` as its arguments which can be called to seal the fate of the created promise. */ @@ -72,13 +72,11 @@ declare class Promise implements Promise.Thenable { * * Alias `.lastly();` for compatibility with earlier ECMAScript version. */ - finally(handler: (value: R) => Promise.Thenable): Promise; - finally(handler: (value: R) => R): Promise; - finally(handler: (value: R) => void): Promise; + finally(handler: () => Promise.Thenable): Promise; + finally(handler: () => U): Promise; - lastly(handler: (value: R) => Promise.Thenable): Promise; - lastly(handler: (value: R) => R): Promise; - lastly(handler: (value: R) => void): Promise; + lastly(handler: () => Promise.Thenable): Promise; + lastly(handler: () => U): Promise; /** * Create a promise that follows this promise, but is bound to the given `thisArg` value. A bound promise will call its handlers with the bound value set to `this`. Additionally promises derived from a bound promise will also be bound promises with the same `thisArg` binding as the original promise. @@ -88,10 +86,16 @@ declare class Promise implements Promise.Thenable { /** * Like `.then()`, but any unhandled rejection that ends up here will be thrown as an error. */ - done(onFulfilled: (value: R) => Promise.Thenable, onRejected: (error: any) => Promise.Thenable, onProgress?: (note: any) => any): Promise; - done(onFulfilled: (value: R) => Promise.Thenable, onRejected?: (error: any) => U, onProgress?: (note: any) => any): Promise; - done(onFulfilled: (value: R) => U, onRejected: (error: any) => Promise.Thenable, onProgress?: (note: any) => any): Promise; - done(onFulfilled?: (value: R) => U, onRejected?: (error: any) => U, onProgress?: (note: any) => any): Promise; + done(onFulfilled: (value: R) => Promise.Thenable, onRejected: (error: any) => Promise.Thenable, onProgress?: (note: any) => any): void; + done(onFulfilled: (value: R) => Promise.Thenable, onRejected?: (error: any) => U, onProgress?: (note: any) => any): void; + done(onFulfilled: (value: R) => U, onRejected: (error: any) => Promise.Thenable, onProgress?: (note: any) => any): void; + done(onFulfilled?: (value: R) => U, onRejected?: (error: any) => U, onProgress?: (note: any) => any): void; + + /** + * Like `.finally()`, but not called for rejections. + */ + tap(onFulFill: (value: R) => Promise.Thenable): Promise; + tap(onFulfill: (value: R) => U): Promise; /** * Shorthand for `.then(null, null, handler);`. Attach a progress handler that will be called if this promise is progressed. Returns a new promise chained from this promise. @@ -172,6 +176,20 @@ declare class Promise implements Promise.Thenable { */ isResolved(): boolean; + /** + * Get the fulfillment value of the underlying promise. Throws if the promise isn't fulfilled yet. + * + * throws `TypeError` + */ + value(): R; + + /** + * Get the rejection reason for the underlying promise. Throws if the promise isn't rejected yet. + * + * throws `TypeError` + */ + reason(): any; + /** * Synchronously inspect the state of this `promise`. The `PromiseInspection` will represent the state of the promise as snapshotted at the time of calling `.inspect()`. */ @@ -594,6 +612,20 @@ declare module Promise { } export interface RejectionError extends Error { } + export interface OperationalError extends Error { + } + + // Ideally, we'd define e.g. "export class RangeError extends Error {}", + // but as Error is defined as an interface (not a class), TypeScript doesn't + // allow extending Error, only implementing it. + // However, if we want to catch() only a specific error type, we need to pass + // a constructor function to it. So, as a workaround, we define them here as such. + export function RangeError(): RangeError; + export function CancellationError(): CancellationError; + export function TimeoutError(): TimeoutError; + export function TypeError(): TypeError; + export function RejectionError(): RejectionError; + export function OperationalError(): OperationalError; export interface Thenable { then(onFulfilled: (value: R) => Thenable, onRejected: (error: any) => Thenable): Thenable; @@ -661,8 +693,16 @@ declare module Promise { * * throws `TypeError` */ - error(): any; + reason(): any; } + + /** + * Changes how bluebird schedules calls a-synchronously. + * + * @param scheduler Should be a function that asynchronously schedules + * the calling of the passed in function + */ + export function setScheduler(scheduler: (callback: (...args: any[]) => void) => void): void; } declare module 'bluebird' { From 5ab1bd484034f61fbf688e14eecc28638c36f7ea Mon Sep 17 00:00:00 2001 From: Paulo Cesar Date: Wed, 12 Nov 2014 08:30:07 -0200 Subject: [PATCH 11/15] squash! squash! update angular to released version 1.3+ interval delay isnt optional --- angularjs/angular.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/angularjs/angular.d.ts b/angularjs/angular.d.ts index d28c40e21e..64a9d0652b 100755 --- a/angularjs/angular.d.ts +++ b/angularjs/angular.d.ts @@ -630,7 +630,7 @@ declare module ng { // see http://docs.angularjs.org/api/ng.$interval /////////////////////////////////////////////////////////////////////////// interface IIntervalService { - (func: Function, delay?: number, count?: number, invokeApply?: boolean): IPromise; + (func: Function, delay: number, count?: number, invokeApply?: boolean): IPromise; cancel(promise: IPromise): boolean; } From f5f114f1e65756500789c0b39dd5d99981bcd8a7 Mon Sep 17 00:00:00 2001 From: John Vilk Date: Wed, 12 Nov 2014 13:07:51 -0500 Subject: [PATCH 12/15] Adding fs.(Read|Write)Stream.close(). It's undocumented, but it is present in the source code and programs rely on it. --- node/node-tests.ts | 1 + node/node.d.ts | 22 +++++++++++++--------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/node/node-tests.ts b/node/node-tests.ts index a8c13f8b0c..7f59ab9859 100644 --- a/node/node-tests.ts +++ b/node/node-tests.ts @@ -91,6 +91,7 @@ function stream_readable_pipe_test() { var z = zlib.createGzip(); var w = fs.createWriteStream('file.txt.gz'); r.pipe(z).pipe(w); + r.close(); } //////////////////////////////////////////////////// diff --git a/node/node.d.ts b/node/node.d.ts index 7edbdfd609..2405b4408d 100644 --- a/node/node.d.ts +++ b/node/node.d.ts @@ -721,8 +721,8 @@ declare module "net" { setKeepAlive(enable?: boolean, initialDelay?: number): void; address(): { port: number; family: string; address: string; }; unref(): void; - ref(): void; - + ref(): void; + remoteAddress: string; remotePort: number; bytesRead: number; @@ -770,13 +770,13 @@ declare module "dgram" { port: number; size: number; } - + interface AddressInfo { - address: string; - family: string; - port: number; + address: string; + family: string; + port: number; } - + export function createSocket(type: string, callback?: (msg: Buffer, rinfo: RemoteInfo) => void): Socket; interface Socket extends events.EventEmitter { @@ -823,8 +823,12 @@ declare module "fs" { close(): void; } - export interface ReadStream extends stream.Readable {} - export interface WriteStream extends stream.Writable {} + export interface ReadStream extends stream.Readable { + close(): void; + } + export interface WriteStream extends stream.Writable { + close(): void; + } export function rename(oldPath: string, newPath: string, callback?: (err?: NodeJS.ErrnoException) => void): void; export function renameSync(oldPath: string, newPath: string): void; From 161a175f8584bb9fb242fde066fcd02afac0c8b4 Mon Sep 17 00:00:00 2001 From: Guido Zuidhof Date: Wed, 12 Nov 2014 20:53:16 +0100 Subject: [PATCH 13/15] Add minilog typings --- CONTRIBUTORS.md | 3 +- minilog/minilog-tests.ts | 63 ++++++++++++++++++++++++++ minilog/minilog.d.ts | 98 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 163 insertions(+), 1 deletion(-) create mode 100644 minilog/minilog-tests.ts create mode 100644 minilog/minilog.d.ts diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index e10ca14d4c..c45542a9f3 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -1,4 +1,4 @@ -# Contributors +# Contributors This is a non-exhaustive list of definitions and their creators. If you created a definition but are not listed then feel free to send a pull request on this file with your name and url. @@ -280,6 +280,7 @@ All definitions files include a header with the author and editors, so at some p * [md5.js](http://labs.cybozu.co.jp/blog/mitsunari/2007/07/md5js_1.html) (by [MIZUNE Pine](https://github.com/pine613)) * [Microsoft Ajax](http://msdn.microsoft.com/en-us/library/ee341002(v=vs.100).aspx) (by [Patrick Magee](https://github.com/pjmagee)) * [Microsoft Live Connect](http://msdn.microsoft.com/en-us/library/live/hh243643.aspx) (by [John Vilk](https://github.com/jvilk)) +* [minilog](http://mixu.net/minilog/index.html) (by [Guido Zuidhof](https://github.com/Rahazan)) * [Minimatch](https://github.com/isaacs/minimatch) (by [vvakame](https://github.com/vvakame)) * [minimist](https://github.com/substack/minimist) (by [Bart van der Schoor](https://github.com/Bartvds)) * [Mithril](http://lhorie.github.io/mithril) (by [Leo Horie](https://github.com/lhorie) and [Chris Bowdon](https://github.com/cbowdon)) diff --git a/minilog/minilog-tests.ts b/minilog/minilog-tests.ts new file mode 100644 index 0000000000..3a9bb0f4de --- /dev/null +++ b/minilog/minilog-tests.ts @@ -0,0 +1,63 @@ +// Type definitions for minilog v2 +// Project: https://github.com/mixu/minilog +// Definitions by: Guido +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/// + + +//Following are example snippets from mixu.net/minilog + +var log = Minilog('app'); +Minilog.enable(); + +log + .debug('debug message') + .info('info message') + .warn('warning') + .error('this is an error message'); + +Minilog.pipe(Minilog.backends.console.formatWithStack) + .pipe(Minilog.backends.console); + + +Minilog +// formatter + .pipe(Minilog.backends.console.formatClean) +// backend + .pipe(Minilog.backends.console); + + +Minilog.pipe(Minilog.suggest) // filter + .pipe(Minilog.defaultFormatter) // formatter + .pipe(Minilog.defaultBackend); // backend - e.g. the console + +Minilog.suggest.deny(/mymodule\/.*/, 'warn'); + +Minilog + .suggest + .clear() + .deny('foo', 'warn'); +Minilog.enable(); + +Minilog.suggest.defaultResult = false; +Minilog + .suggest + .clear() + .allow('bar', 'info'); +Minilog.enable(); + + +var myFilter = new Minilog.Filter(); +// allow any logs from the namespace/module "foo", level >= 'info +myFilter.allow('foo', 'debug'); +// deny any logs where the module name matches "bar.*", level < 'warn' +// e.g. only let through "warn" and "error" +myFilter.deny(new RegExp('bar.*', 'warn')); + +// now, create a custom pipe +Minilog.pipe(myFilter) + .pipe(Minilog.defaultFormatter) + .pipe(Minilog.defaultBackend); + + diff --git a/minilog/minilog.d.ts b/minilog/minilog.d.ts new file mode 100644 index 0000000000..d9d1695bf2 --- /dev/null +++ b/minilog/minilog.d.ts @@ -0,0 +1,98 @@ +// Type definitions for minilog v2 +// Project: https://github.com/mixu/minilog +// Definitions by: Guido +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +//These type definitions are not complete, although basic usage should be typed. +interface Minilog { + debug(msg: any): Minilog; + info(msg: any): Minilog; + log(msg: any): Minilog; + warn(msg: any): Minilog; + error(msg: any): Minilog; +} + +declare function Minilog(namespace: string): Minilog; + +declare module Minilog { + export function enable(): Minilog; + export function disable() : Minilog; + export function pipe(dest: any): Transform; + + export var suggest: Filter; + export var backends: Minilog.MinilogBackends; + + export var defaultBackend: any; + export var defaultFormatter: string; + + + export class Filter extends Transform{ + + /** + * Adds an entry to the whitelist + * Returns this filter + */ + allow(name: any, level?: any): Filter; + /** + * Adds an entry to the blacklist + * Returns this filter + */ + deny(name: any, level?: any): Filter; + /** + * Empties the whitelist and blacklist + * Returns this filter + */ + clear(): Filter; + + test(name:any, level:any): boolean; + + /** + * specifies the behavior when a log line doesn't match either the whitelist or the blacklist. + The default is true (= "allow by default") - lines that do not match the whitelist or the blacklist are not filtered (e.g. ). + If you want to flip the default so that lines are filtered unless they are on the whitelist, set this to false (= "deny by default"). + */ + defaultResult: boolean; + + /** + * controls whether the filter is enabled. Default: true + */ + enabled: boolean; + } + + + export interface MinilogBackends { + array: any; + browser: any; + console: Console; + localstorage: any; + jQuery: any; + } + + export class Console extends Transform{ + + /** + * List of available formatters + */ + formatters: string[]; + + //Only available on client + color: Transform; + minilog: Transform; + + //Only available on backend + formatClean: Transform; + formatColor: Transform; + formatNpm: Transform; + formatLearnboost: Transform; + formatMinilog: Transform; + formatWithStack: Transform; + } + + export class Transform { + write(name: any, level: any, args: any): void; + pipe(dest: any): any; + unpipe(from: any): Transform; + mixin(dest: any): void; + } + +} \ No newline at end of file From 5e5b95afa3a32cf7e9a40cc5d4bbe2f0b8a5674c Mon Sep 17 00:00:00 2001 From: MIZUNE Pine Date: Thu, 13 Nov 2014 06:36:43 +0900 Subject: [PATCH 14/15] Add content-type --- content-type/content-type-test.ts | 47 +++++++++++++++++++++++++++++++ content-type/content-type.d.ts | 32 +++++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 content-type/content-type-test.ts create mode 100644 content-type/content-type.d.ts diff --git a/content-type/content-type-test.ts b/content-type/content-type-test.ts new file mode 100644 index 0000000000..4bf63e2ab6 --- /dev/null +++ b/content-type/content-type-test.ts @@ -0,0 +1,47 @@ +/// + +import MediaType = require('content-type'); + +// https://github.com/deoxxa/content-type/blob/master/README.md +function new_test(): void { + var p = new MediaType('text/html;level=1;q=0.5'); + p.q === 0.5; + p.params.level === "1"; + + var q = new MediaType('application/json', { profile: 'http://example.com/schema.json' }); + q.type === "application/json"; + q.params.profile === "http://example.com/schema.json"; + + q.q = 1; + q.toString() === 'application/json;q=1;profile="http://example.com/schema.json"'; +} + +function mediaCmp_test(): void { + MediaType.mediaCmp(MediaType.parseMedia('text/html'), MediaType.parseMedia('text/html')) === 0; + MediaType.mediaCmp(MediaType.parseMedia('*/*'), MediaType.parseMedia('text/html')) === 1; + MediaType.mediaCmp(MediaType.parseMedia('text/html;level=1'), MediaType.parseMedia('text/html')) === -1; + MediaType.mediaCmp(MediaType.parseMedia('application/json;profile="v1.json"'), MediaType.parseMedia('application/json;profile="v2.json"')) === null; +} + +// https://github.com/deoxxa/content-type/blob/master/example.js +function example(): void { + var representations = [ + 'application/json', + 'text/html', + 'application/json;profile="schema.json"', + 'application/json;profile="different.json"', + ]; + + var accept = [ + 'text/html;q=0.50', + '*/*;q=0.01', + 'application/json;profile=different.json', + 'application/json;profile="a,b;c.json?d=1;f=2";q=0.2', + ]; + + console.log('Formats:\n\t' + representations.map(MediaType.parseMedia).join('\n\t')); + + console.log('Accept:\n\t' + accept.map(MediaType.parseMedia).join('\n\t')); + + console.log('Selected:', (MediaType.select(representations.map(MediaType.parseMedia), accept.map(MediaType.parseMedia)) || 'None').toString()); +} \ No newline at end of file diff --git a/content-type/content-type.d.ts b/content-type/content-type.d.ts new file mode 100644 index 0000000000..fbca9c96b3 --- /dev/null +++ b/content-type/content-type.d.ts @@ -0,0 +1,32 @@ +// Type definitions for content-type v0.0.1 +// Project: https://github.com/deoxxa/content-type +// Definitions by: Pine Mizune +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +declare module ContentType { + interface MediaType { + type: string; + q?: number; + params: any; + toString(): string; + } + + interface SelectOptions { + sortAvailable?: boolean; + sortAccepted?: boolean; + } + + interface MediaTypeStatic { + new (s: string, p?: any): MediaType; + parseMedia(type: string): MediaType; + splitQuotedString(str: string, delimiter?: string, quote?: string): string[]; + splitContentTypes(str: string): string[]; + select(availableTypes: MediaType[], acceptedTypes: MediaType[], options?: SelectOptions): string; + mediaCmp(a: MediaType, b: MediaType): number; + } +} + +declare module "content-type" { + var x: ContentType.MediaTypeStatic; + export = x; +} \ No newline at end of file From 31b873c6b58a8176aa10e9304c33b542b0b3cc12 Mon Sep 17 00:00:00 2001 From: tgfjt Date: Thu, 13 Nov 2014 11:47:03 +0900 Subject: [PATCH 15/15] added validator/validator.d.ts for chriso/validator.js @3.22.1 --- CONTRIBUTORS.md | 1 + validator/validator-tests.ts | 106 +++++++++++++++++++ validator/validator.d.ts | 190 +++++++++++++++++++++++++++++++++++ 3 files changed, 297 insertions(+) create mode 100644 validator/validator-tests.ts create mode 100644 validator/validator.d.ts diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index e10ca14d4c..1ab702c85b 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -423,6 +423,7 @@ All definitions files include a header with the author and editors, so at some p * [urlrouter](https://github.com/fengmk2/urlrouter) (by [Carlos Ballesteros Velasco](https://github.com/soywiz)) * [UUID.js](https://github.com/LiosK/UUID.js) (by [Jason Jarrett](https://github.com/staxmanade)) * [Valerie](https://github.com/davewatts/valerie) (by [Howard Richards](https://github.com/conficient)) +* [validator](https://github.com/chriso/validator.js) (by [tgfjt](https://github.com/tgfjt)) * [Velocity](http://velocityjs.org/) (by [Greg Smith](https://github.com/smrq)) * [Viewporter](https://github.com/zynga/viewporter) (by [Boris Yankov](https://github.com/borisyankov)) * [Vimeo](http://developer.vimeo.com/player/js-api) (by [Daz Wilkin](https://github.com/DazWilkin/)) diff --git a/validator/validator-tests.ts b/validator/validator-tests.ts new file mode 100644 index 0000000000..b7f45d4271 --- /dev/null +++ b/validator/validator-tests.ts @@ -0,0 +1,106 @@ +/// + +import validator = require("validator"); + + +validator.extend("isTest", function(str) { + return !str; +}); + +validator.equals("abc", "Abc"); + +validator.contains("foo", "foobar"); + +validator.matches("foobar", "foo/i"); + +validator.isEmail("sample"); + +validator.isURL("sample"); + +validator.isFQDN("sample"); + +validator.isIP("sample"); + +validator.isAlpha("sample"); + +validator.isNumeric("sample"); + +validator.isAlphanumeric("sample"); + +validator.isBase64("sample"); + +validator.isHexadecimal("sample"); + +validator.isHexColor("sample"); + +validator.isLowercase("sample"); + +validator.isUppercase("sample"); + +validator.isInt("sample"); + +validator.isFloat("sample"); + +validator.isDivisibleBy("sample", 2); + +validator.isNull("sample"); + +validator.isLength("sample", 3, 5); + +validator.isByteLength("sample", 3); + +validator.isUUID("sample"); + +validator.isDate("sample"); + +validator.isAfter("sample"); + +validator.isBefore("sample"); + +validator.isIn("sample", []); + +validator.isCreditCard("sample"); + +validator.isISBN("sample"); + +validator.isJSON("sample"); + +validator.isMultibyte("sample"); + +validator.isAscii("sample"); + +validator.isFullWidth("sample"); + +validator.isHalfWidth("sample"); + +validator.isVariableWidth("sample"); + +validator.isSurrogatePair("sample"); + +validator.isMongoId("sample"); + +validator.toString(123); + +validator.toDate(1225); + +validator.toFloat('011'); + +validator.toInt('aa'); + +validator.toBoolean('yes!'); + +validator.trim(' triming '); + +validator.ltrim(' triming '); + +validator.rtrim(' triming '); + +validator.escape('