mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-12-04 12:11:47 +00:00
Angular sub packages (#10170)
* move angular-animate.d.ts to its own folder * Make angular-animate a module, and use module augmentation to update the angular module * Move angular-cookies.d.ts to its own folder * Make angular-cookies a module, and use module augmentation to update the angular module * Remove outdated readme * Move angular-mocks.d.ts to its own folder * Make angular-mocks a module, and use module augmentation to update the angular module * Move angular-resource.d.ts to its own folder * Make angular-resource a module, and use module augmentation to update the angular module * Move angular-route.d.ts to its own folder * Make angular-route a module, and use module augmentation to update the angular module * Move angular-santize.d.ts to its own folder * Make angular-sanitize a module, and use module augmentation to update the angular module
This commit is contained in:
@@ -0,0 +1,169 @@
|
||||
|
||||
import IHttpPromiseCallbackArg = angular.IHttpPromiseCallbackArg;
|
||||
|
||||
interface IMyData {}
|
||||
interface IMyHttpPromiseCallbackArg extends IHttpPromiseCallbackArg<IMyData> {}
|
||||
interface IMyResource extends angular.resource.IResource<IMyResource> { }
|
||||
interface IMyResourceClass extends angular.resource.IResourceClass<IMyResource> { }
|
||||
|
||||
///////////////////////////////////////
|
||||
// IActionDescriptor
|
||||
///////////////////////////////////////
|
||||
var actionDescriptor: angular.resource.IActionDescriptor;
|
||||
|
||||
angular.injector(['ng']).invoke(function ($cacheFactory: angular.ICacheFactoryService) {
|
||||
actionDescriptor.method = 'method action';
|
||||
actionDescriptor.params = { key: 'value' };
|
||||
actionDescriptor.url = '/api/test-url/';
|
||||
actionDescriptor.isArray = true;
|
||||
actionDescriptor.transformRequest = function () { };
|
||||
actionDescriptor.transformRequest = [function () { }];
|
||||
actionDescriptor.transformResponse = function () { };
|
||||
actionDescriptor.transformResponse = [function () { }];
|
||||
actionDescriptor.headers = { header: 'value' };
|
||||
actionDescriptor.cache = true;
|
||||
actionDescriptor.cache = $cacheFactory('cacheId');
|
||||
actionDescriptor.timeout = 1000;
|
||||
actionDescriptor.withCredentials = true;
|
||||
actionDescriptor.responseType = 'response type';
|
||||
actionDescriptor.interceptor = {
|
||||
response: function<IMyData> () { return <IMyHttpPromiseCallbackArg>{}; },
|
||||
responseError: function () {}
|
||||
};
|
||||
actionDescriptor.cancellable = true;
|
||||
});
|
||||
|
||||
|
||||
///////////////////////////////////////
|
||||
// IResourceClass
|
||||
///////////////////////////////////////
|
||||
var resourceClass: IMyResourceClass;
|
||||
var resource: IMyResource;
|
||||
var resourceArray: angular.resource.IResourceArray<IMyResource>;
|
||||
|
||||
resource = resourceClass.delete();
|
||||
resource = resourceClass.delete({ key: 'value' });
|
||||
resource = resourceClass.delete({ key: 'value' }, function () { });
|
||||
resource = resourceClass.delete(function () { });
|
||||
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.$cancelRequest();
|
||||
|
||||
resource = resourceClass.get();
|
||||
resource = resourceClass.get({ key: 'value' });
|
||||
resource = resourceClass.get({ key: 'value' }, function () { });
|
||||
resource = resourceClass.get(function () { });
|
||||
resource = resourceClass.get(function () { }, function () { });
|
||||
resource = resourceClass.get({ key: 'value' }, { key: 'value' });
|
||||
resource = resourceClass.get({ key: 'value' }, { key: 'value' }, function () { });
|
||||
resource = resourceClass.get({ key: 'value' }, { key: 'value' }, function () { }, function () { });
|
||||
|
||||
resourceArray = resourceClass.query();
|
||||
resourceArray = resourceClass.query({ key: 'value' });
|
||||
resourceArray = resourceClass.query({ key: 'value' }, function () { });
|
||||
resourceArray = resourceClass.query(function () { });
|
||||
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: angular.resource.IResourceArray<IMyResource>) {});
|
||||
|
||||
resource = resourceClass.remove();
|
||||
resource = resourceClass.remove({ key: 'value' });
|
||||
resource = resourceClass.remove({ key: 'value' }, function () { });
|
||||
resource = resourceClass.remove(function () { });
|
||||
resource = resourceClass.remove(function () { }, function () { });
|
||||
resource = resourceClass.remove({ key: 'value' }, { key: 'value' });
|
||||
resource = resourceClass.remove({ key: 'value' }, { key: 'value' }, function () { });
|
||||
resource = resourceClass.remove({ key: 'value' }, { key: 'value' }, function () { }, function () { });
|
||||
|
||||
resource = resourceClass.save();
|
||||
resource = resourceClass.save({ key: 'value' });
|
||||
resource = resourceClass.save({ key: 'value' }, function () { });
|
||||
resource = resourceClass.save(function () { });
|
||||
resource = resourceClass.save(function () { }, function () { });
|
||||
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 : angular.IPromise<IMyResource>;
|
||||
var arrayPromise : angular.IPromise<IMyResource[]>;
|
||||
var json: 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: angular.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 () { });
|
||||
|
||||
json = resource.toJSON();
|
||||
|
||||
///////////////////////////////////////
|
||||
// IResourceService
|
||||
///////////////////////////////////////
|
||||
var resourceService: angular.resource.IResourceService;
|
||||
resourceClass = resourceService<IMyResource, IMyResourceClass>('test');
|
||||
resourceClass = resourceService<IMyResource>('test');
|
||||
resourceClass = resourceService('test');
|
||||
|
||||
///////////////////////////////////////
|
||||
// IModule
|
||||
///////////////////////////////////////
|
||||
var mod: ng.IModule;
|
||||
var resourceServiceFactoryFunction: angular.resource.IResourceServiceFactoryFunction<IMyResource>;
|
||||
var resourceService: angular.resource.IResourceService;
|
||||
|
||||
resourceClass = resourceServiceFactoryFunction<IMyResourceClass>(resourceService);
|
||||
|
||||
resourceServiceFactoryFunction = function (resourceService: angular.resource.IResourceService) { return <any>resourceClass; };
|
||||
mod = mod.factory('factory name', resourceServiceFactoryFunction);
|
||||
|
||||
///////////////////////////////////////
|
||||
// IResource
|
||||
///////////////////////////////////////
|
||||
|
||||
|
||||
///////////////////////////////////////
|
||||
// IResourceServiceProvider
|
||||
///////////////////////////////////////
|
||||
var resourceServiceProvider: angular.resource.IResourceServiceProvider;
|
||||
resourceServiceProvider.defaults.stripTrailingSlashes = false;
|
||||
Vendored
+192
@@ -0,0 +1,192 @@
|
||||
// Type definitions for Angular JS 1.5 (ngResource module)
|
||||
// Project: http://angularjs.org
|
||||
// Definitions by: Diego Vilar <http://github.com/diegovilar>, Michael Jess <http://github.com/miffels>
|
||||
// Definitions: https://github.com/daptiv/DefinitelyTyped
|
||||
|
||||
declare var _: string;
|
||||
export = _;
|
||||
|
||||
import * as angular from 'angular';
|
||||
|
||||
declare module 'angular' {
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// ngResource module (angular-resource.js)
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
namespace resource {
|
||||
/**
|
||||
* Currently supported options for the $resource factory options argument.
|
||||
*/
|
||||
interface IResourceOptions {
|
||||
/**
|
||||
* If true then the trailing slashes from any calculated URL will be stripped (defaults to true)
|
||||
*/
|
||||
stripTrailingSlashes?: boolean;
|
||||
/**
|
||||
* If true, the request made by a "non-instance" call will be cancelled (if not already completed) by calling
|
||||
* $cancelRequest() on the call's return value. This can be overwritten per action. (Defaults to false.)
|
||||
*/
|
||||
cancellable?: boolean;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// ResourceService
|
||||
// see http://docs.angularjs.org/api/ngResource.$resource
|
||||
// Most part of the following definitions were achieved by analyzing the
|
||||
// actual implementation, since the documentation doesn't seem to cover
|
||||
// that deeply.
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
interface IResourceService {
|
||||
(url: string, paramDefaults?: any,
|
||||
/** example: {update: { method: 'PUT' }, delete: deleteDescriptor }
|
||||
where deleteDescriptor : IActionDescriptor */
|
||||
actions?: any, options?: IResourceOptions): IResourceClass<IResource<any>>;
|
||||
<T, U>(url: string, paramDefaults?: any,
|
||||
/** example: {update: { method: 'PUT' }, delete: deleteDescriptor }
|
||||
where deleteDescriptor : IActionDescriptor */
|
||||
actions?: any, options?: IResourceOptions): U;
|
||||
<T>(url: string, paramDefaults?: any,
|
||||
/** example: {update: { method: 'PUT' }, delete: deleteDescriptor }
|
||||
where deleteDescriptor : IActionDescriptor */
|
||||
actions?: any, options?: IResourceOptions): IResourceClass<T>;
|
||||
}
|
||||
|
||||
// Just a reference to facilitate describing new actions
|
||||
interface IActionDescriptor {
|
||||
method: string;
|
||||
params?: any;
|
||||
url?: string;
|
||||
isArray?: boolean;
|
||||
transformRequest?: angular.IHttpRequestTransformer | angular.IHttpRequestTransformer[];
|
||||
transformResponse?: angular.IHttpResponseTransformer | angular.IHttpResponseTransformer[];
|
||||
headers?: any;
|
||||
cache?: boolean | angular.ICacheObject;
|
||||
/**
|
||||
* Note: In contrast to $http.config, promises are not supported in $resource, because the same value
|
||||
* would be used for multiple requests. If you are looking for a way to cancel requests, you should
|
||||
* use the cancellable option.
|
||||
*/
|
||||
timeout?: number
|
||||
cancellable?: boolean;
|
||||
withCredentials?: boolean;
|
||||
responseType?: string;
|
||||
interceptor?: angular.IHttpInterceptor;
|
||||
}
|
||||
|
||||
// Allow specify more resource methods
|
||||
// No need to add duplicates for all four overloads.
|
||||
interface IResourceMethod<T> {
|
||||
(): T;
|
||||
(params: Object): T;
|
||||
(success: Function, error?: Function): T;
|
||||
(params: Object, success: Function, error?: Function): T;
|
||||
(params: Object, data: Object, success?: Function, error?: Function): T;
|
||||
}
|
||||
|
||||
// Allow specify resource moethod which returns the array
|
||||
// No need to add duplicates for all four overloads.
|
||||
interface IResourceArrayMethod<T> {
|
||||
(): IResourceArray<T>;
|
||||
(params: Object): IResourceArray<T>;
|
||||
(success: Function, error?: Function): IResourceArray<T>;
|
||||
(params: Object, success: Function, error?: Function): IResourceArray<T>;
|
||||
(params: Object, data: Object, success?: Function, error?: Function): IResourceArray<T>;
|
||||
}
|
||||
|
||||
// Baseclass for everyresource with default actions.
|
||||
// If you define your new actions for the resource, you will need
|
||||
// to extend this interface and typecast the ResourceClass to it.
|
||||
//
|
||||
// In case of passing the first argument as anything but a function,
|
||||
// it's gonna be considered data if the action method is POST, PUT or
|
||||
// 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: IResourceMethod<T>;
|
||||
|
||||
query: IResourceArrayMethod<T>;
|
||||
|
||||
save: IResourceMethod<T>;
|
||||
|
||||
remove: IResourceMethod<T>;
|
||||
|
||||
delete: IResourceMethod<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(): angular.IPromise<T>;
|
||||
$get(params?: Object, success?: Function, error?: Function): angular.IPromise<T>;
|
||||
$get(success: Function, error?: Function): angular.IPromise<T>;
|
||||
|
||||
$query(): angular.IPromise<IResourceArray<T>>;
|
||||
$query(params?: Object, success?: Function, error?: Function): angular.IPromise<IResourceArray<T>>;
|
||||
$query(success: Function, error?: Function): angular.IPromise<IResourceArray<T>>;
|
||||
|
||||
$save(): angular.IPromise<T>;
|
||||
$save(params?: Object, success?: Function, error?: Function): angular.IPromise<T>;
|
||||
$save(success: Function, error?: Function): angular.IPromise<T>;
|
||||
|
||||
$remove(): angular.IPromise<T>;
|
||||
$remove(params?: Object, success?: Function, error?: Function): angular.IPromise<T>;
|
||||
$remove(success: Function, error?: Function): angular.IPromise<T>;
|
||||
|
||||
$delete(): angular.IPromise<T>;
|
||||
$delete(params?: Object, success?: Function, error?: Function): angular.IPromise<T>;
|
||||
$delete(success: Function, error?: Function): angular.IPromise<T>;
|
||||
|
||||
$cancelRequest(): void;
|
||||
|
||||
/** the promise of the original server interaction that created this instance. **/
|
||||
$promise: angular.IPromise<T>;
|
||||
$resolved: boolean;
|
||||
toJSON(): T;
|
||||
}
|
||||
|
||||
/**
|
||||
* Really just a regular Array object with $promise and $resolve attached to it
|
||||
*/
|
||||
interface IResourceArray<T> extends Array<T & IResource<T>> {
|
||||
/** the promise of the original server interaction that created this collection. **/
|
||||
$promise: angular.IPromise<IResourceArray<T>>;
|
||||
$resolved: boolean;
|
||||
}
|
||||
|
||||
/** when creating a resource factory via IModule.factory */
|
||||
interface IResourceServiceFactoryFunction<T> {
|
||||
($resource: angular.resource.IResourceService): IResourceClass<T>;
|
||||
<U extends IResourceClass<T>>($resource: angular.resource.IResourceService): U;
|
||||
}
|
||||
|
||||
// IResourceServiceProvider used to configure global settings
|
||||
interface IResourceServiceProvider extends angular.IServiceProvider {
|
||||
|
||||
defaults: IResourceOptions;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/** extensions to base ng based on using angular-resource */
|
||||
interface IModule {
|
||||
/** creating a resource service factory */
|
||||
factory(name: string, resourceServiceFactoryFunction: angular.resource.IResourceServiceFactoryFunction<any>): IModule;
|
||||
}
|
||||
}
|
||||
|
||||
declare global {
|
||||
interface Array<T> {
|
||||
/** the promise of the original server interaction that created this collection. **/
|
||||
$promise: angular.IPromise<Array<T>>;
|
||||
$resolved: boolean;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"angular-resource-tests.ts"
|
||||
],
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"target": "es6",
|
||||
"noImplicitAny": true,
|
||||
"strictNullChecks": false,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": false
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user