mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-08-20 12:00:53 +08:00
Merge pull request #2005 from miffels/master
Enhanced call interface definitions
This commit is contained in:
@@ -19,7 +19,7 @@ actionDescriptor.params = { key: 'value' };
|
||||
///////////////////////////////////////
|
||||
var resourceClass: IMyResourceClass;
|
||||
var resource: IMyResource;
|
||||
var resourceArray: IMyResource[];
|
||||
var resourceArray: ng.resource.IResourceArray<IMyResource>;
|
||||
|
||||
resource = resourceClass.delete();
|
||||
resource = resourceClass.delete({ key: 'value' });
|
||||
@@ -29,6 +29,7 @@ resource = resourceClass.delete(function () { }, function () { });
|
||||
resource = resourceClass.delete({ key: 'value' }, { key: 'value' });
|
||||
resource = resourceClass.delete({ key: 'value' }, { key: 'value' }, function () { });
|
||||
resource = resourceClass.delete({ key: 'value' }, { key: 'value' }, function () { }, function () { });
|
||||
resource.$promise.then(function(data: IMyResource) {});
|
||||
|
||||
resource = resourceClass.get();
|
||||
resource = resourceClass.get({ key: 'value' });
|
||||
@@ -47,6 +48,8 @@ resourceArray = resourceClass.query(function () { }, function () { });
|
||||
resourceArray = resourceClass.query({ key: 'value' }, { key: 'value' });
|
||||
resourceArray = resourceClass.query({ key: 'value' }, { key: 'value' }, function () { });
|
||||
resourceArray = resourceClass.query({ key: 'value' }, { key: 'value' }, function () { }, function () { });
|
||||
resourceArray.push(resource);
|
||||
resourceArray.$promise.then(function(data: ng.resource.IResourceArray<IMyResource>) {});
|
||||
|
||||
resource = resourceClass.remove();
|
||||
resource = resourceClass.remove({ key: 'value' });
|
||||
@@ -66,6 +69,50 @@ resource = resourceClass.save({ key: 'value' }, { key: 'value' });
|
||||
resource = resourceClass.save({ key: 'value' }, { key: 'value' }, function () { });
|
||||
resource = resourceClass.save({ key: 'value' }, { key: 'value' }, function () { }, function () { });
|
||||
|
||||
///////////////////////////////////////
|
||||
// IResource
|
||||
///////////////////////////////////////
|
||||
|
||||
var promise : ng.IPromise<IMyResource>;
|
||||
var arrayPromise : ng.IPromise<IMyResource[]>;
|
||||
|
||||
promise = resource.$delete();
|
||||
promise = resource.$delete({ key: 'value' });
|
||||
promise = resource.$delete({ key: 'value' }, function () { });
|
||||
promise = resource.$delete(function () { });
|
||||
promise = resource.$delete(function () { }, function () { });
|
||||
promise = resource.$delete({ key: 'value' }, function () { }, function () { });
|
||||
promise.then(function(data: IMyResource) {});
|
||||
|
||||
promise = resource.$get();
|
||||
promise = resource.$get({ key: 'value' });
|
||||
promise = resource.$get({ key: 'value' }, function () { });
|
||||
promise = resource.$get(function () { });
|
||||
promise = resource.$get(function () { }, function () { });
|
||||
promise = resource.$get({ key: 'value' }, function () { }, function () { });
|
||||
|
||||
arrayPromise = resourceArray[0].$query();
|
||||
arrayPromise = resourceArray[0].$query({ key: 'value' });
|
||||
arrayPromise = resourceArray[0].$query({ key: 'value' }, function () { });
|
||||
arrayPromise = resourceArray[0].$query(function () { });
|
||||
arrayPromise = resourceArray[0].$query(function () { }, function () { });
|
||||
arrayPromise = resourceArray[0].$query({ key: 'value' }, function () { }, function () { });
|
||||
arrayPromise.then(function(data: ng.resource.IResourceArray<IMyResource>) {});
|
||||
|
||||
promise = resource.$remove();
|
||||
promise = resource.$remove({ key: 'value' });
|
||||
promise = resource.$remove({ key: 'value' }, function () { });
|
||||
promise = resource.$remove(function () { });
|
||||
promise = resource.$remove(function () { }, function () { });
|
||||
promise = resource.$remove({ key: 'value' }, function () { }, function () { });
|
||||
|
||||
promise = resource.$save();
|
||||
promise = resource.$save({ key: 'value' });
|
||||
promise = resource.$save({ key: 'value' }, function () { });
|
||||
promise = resource.$save(function () { });
|
||||
promise = resource.$save(function () { }, function () { });
|
||||
promise = resource.$save({ key: 'value' }, function () { }, function () { });
|
||||
|
||||
///////////////////////////////////////
|
||||
// IResourceService
|
||||
///////////////////////////////////////
|
||||
@@ -85,3 +132,7 @@ resourceClass = resourceServiceFactoryFunction<IMyResourceClass>(resourceService
|
||||
|
||||
resourceServiceFactoryFunction = function (resourceService: ng.resource.IResourceService) { return <any>resourceClass; };
|
||||
mod = mod.factory('factory name', resourceServiceFactoryFunction);
|
||||
|
||||
///////////////////////////////////////
|
||||
// IResource
|
||||
///////////////////////////////////////
|
||||
Vendored
+61
-44
@@ -1,6 +1,6 @@
|
||||
// Type definitions for Angular JS 1.2 (ngResource module)
|
||||
// Project: http://angularjs.org
|
||||
// Definitions by: Diego Vilar <http://github.com/diegovilar>
|
||||
// Definitions by: Diego Vilar <http://github.com/diegovilar>, Michael Jess <http://github.com/miffels> (minor enhancements)
|
||||
// Definitions: https://github.com/daptiv/DefinitelyTyped
|
||||
|
||||
/// <reference path="angular.d.ts" />
|
||||
@@ -50,67 +50,84 @@ declare module ng.resource {
|
||||
// PATCH (in other words, methods with body). Otherwise, it's going
|
||||
// to be considered as parameters to the request.
|
||||
// https://github.com/angular/angular.js/blob/v1.2.0/src/ngResource/resource.js#L461-L465
|
||||
//
|
||||
// Only those methods with an HTTP body do have 'data' as first parameter:
|
||||
// https://github.com/angular/angular.js/blob/v1.2.0/src/ngResource/resource.js#L463
|
||||
// More specifically, those methods are POST, PUT and PATCH:
|
||||
// https://github.com/angular/angular.js/blob/v1.2.0/src/ngResource/resource.js#L432
|
||||
//
|
||||
// Also, static calls always return the IResource (or IResourceArray) retrieved
|
||||
// https://github.com/angular/angular.js/blob/v1.2.0/src/ngResource/resource.js#L538-L549
|
||||
interface IResourceClass<T> {
|
||||
new(dataOrParams? : any) : T;
|
||||
get(): T;
|
||||
get(dataOrParams: any): T;
|
||||
get(dataOrParams: any, success: Function): T;
|
||||
get(params: Object): T;
|
||||
get(success: Function, error?: Function): T;
|
||||
get(params: any, data: any, success?: Function, error?: Function): T;
|
||||
get(params: Object, success: Function, error?: Function): T;
|
||||
get(params: Object, data: Object, success?: Function, error?: Function): T;
|
||||
|
||||
query(): IResourceArray<T>;
|
||||
query(params: Object): IResourceArray<T>;
|
||||
query(success: Function, error?: Function): IResourceArray<T>;
|
||||
query(params: Object, success: Function, error?: Function): IResourceArray<T>;
|
||||
query(params: Object, data: Object, success?: Function, error?: Function): IResourceArray<T>;
|
||||
|
||||
save(): T;
|
||||
save(dataOrParams: any): T;
|
||||
save(dataOrParams: any, success: Function): T;
|
||||
save(data: Object): T;
|
||||
save(success: Function, error?: Function): T;
|
||||
save(params: any, data: any, success?: Function, error?: Function): T;
|
||||
query(): T[];
|
||||
query(dataOrParams: any): T[];
|
||||
query(dataOrParams: any, success: Function): T[];
|
||||
query(success: Function, error?: Function): T[];
|
||||
query(params: any, data: any, success?: Function, error?: Function): T[];
|
||||
save(data: Object, success: Function, error?: Function): T;
|
||||
save(params: Object, data: Object, success?: Function, error?: Function): T;
|
||||
|
||||
remove(): T;
|
||||
remove(dataOrParams: any): T;
|
||||
remove(dataOrParams: any, success: Function): T;
|
||||
remove(params: Object): T;
|
||||
remove(success: Function, error?: Function): T;
|
||||
remove(params: any, data: any, success?: Function, error?: Function): T;
|
||||
remove(params: Object, success: Function, error?: Function): T;
|
||||
remove(params: Object, data: Object, success?: Function, error?: Function): T;
|
||||
|
||||
delete(): T;
|
||||
delete(dataOrParams: any): T;
|
||||
delete(dataOrParams: any, success: Function): T;
|
||||
delete(params: Object): T;
|
||||
delete(success: Function, error?: Function): T;
|
||||
delete(params: any, data: any, success?: Function, error?: Function): T;
|
||||
delete(params: Object, success: Function, error?: Function): T;
|
||||
delete(params: Object, data: Object, success?: Function, error?: Function): T;
|
||||
}
|
||||
|
||||
// Instance calls always return the the promise of the request which retrieved the object
|
||||
// https://github.com/angular/angular.js/blob/v1.2.0/src/ngResource/resource.js#L538-L546
|
||||
interface IResource<T> {
|
||||
$get(): T;
|
||||
$get(dataOrParams: any): T;
|
||||
$get(dataOrParams: any, success: Function): T;
|
||||
$get(success: Function, error?: Function): T;
|
||||
$get(params: any, data: any, success?: Function, error?: Function): T;
|
||||
$save(): T;
|
||||
$save(dataOrParams: any): T;
|
||||
$save(dataOrParams: any, success: Function): T;
|
||||
$save(success: Function, error?: Function): T;
|
||||
$save(params: any, data: any, success?: Function, error?: Function): T;
|
||||
$query(): T[];
|
||||
$query(dataOrParams: any): T[];
|
||||
$query(dataOrParams: any, success: Function): T[];
|
||||
$query(success: Function, error?: Function): T[];
|
||||
$query(params: any, data: any, success?: Function, error?: Function): T[];
|
||||
$remove(): T;
|
||||
$remove(dataOrParams: any): T;
|
||||
$remove(dataOrParams: any, success: Function): T;
|
||||
$remove(success: Function, error?: Function): T;
|
||||
$remove(params: any, data: any, success?: Function, error?: Function): T;
|
||||
$delete(): T;
|
||||
$delete(dataOrParams: any): T;
|
||||
$delete(dataOrParams: any, success: Function): T;
|
||||
$delete(success: Function, error?: Function): T;
|
||||
$delete(params: any, data: any, success?: Function, error?: Function): T;
|
||||
|
||||
$get(): ng.IPromise<T>;
|
||||
$get(params?: Object, success?: Function, error?: Function): ng.IPromise<T>;
|
||||
$get(success: Function, error?: Function): ng.IPromise<T>;
|
||||
|
||||
$query(): ng.IPromise<IResourceArray<T>>;
|
||||
$query(params?: Object, success?: Function, error?: Function): ng.IPromise<IResourceArray<T>>;
|
||||
$query(success: Function, error?: Function): ng.IPromise<IResourceArray<T>>;
|
||||
|
||||
$save(): ng.IPromise<T>;
|
||||
$save(params?: Object, success?: Function, error?: Function): ng.IPromise<T>;
|
||||
$save(success: Function, error?: Function): ng.IPromise<T>;
|
||||
|
||||
$remove(): ng.IPromise<T>;
|
||||
$remove(params?: Object, success?: Function, error?: Function): ng.IPromise<T>;
|
||||
$remove(success: Function, error?: Function): ng.IPromise<T>;
|
||||
|
||||
$delete(): ng.IPromise<T>;
|
||||
$delete(params?: Object, success?: Function, error?: Function): ng.IPromise<T>;
|
||||
$delete(success: Function, error?: Function): ng.IPromise<T>;
|
||||
|
||||
/** the promise of the original server interaction that created this instance. **/
|
||||
$promise : ng.IPromise<T>;
|
||||
$resolved : boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Really just a regular Array object with $promise and $resolve attached to it
|
||||
*/
|
||||
interface IResourceArray<T> extends Array<T> {
|
||||
/** the promise of the original server interaction that created this collection. **/
|
||||
$promise : ng.IPromise<IResourceArray<T>>;
|
||||
$resolved : boolean;
|
||||
}
|
||||
|
||||
/** when creating a resource factory via IModule.factory */
|
||||
interface IResourceServiceFactoryFunction<T> {
|
||||
($resource: ng.resource.IResourceService): IResourceClass<T>;
|
||||
|
||||
Reference in New Issue
Block a user