* Added missing nconf.required(keys) and Provider.required(keys) methods. * update to 4.7.0, add querycursor.map() and schema.loadClass() * add error callback for schema.post() * Added playsInline property as introduced in React 15.3.2 * Add definitions for redux-localstorage and main enhancers (#12580) * Add definitions for redux-localstorage * Add definitions for redux-localstorage-filter enhancer * Add definitions for redux-localstorage-debounce enhancer * csurf.d.ts relying on CookieOptions from express It seems express no longer exports `CookieOptions`, we need to import `express-serve-static-core` instead. * Added height property to IDialogOptions * versionKey type * kendo-ui: mark toString() params as optional (#13164) These function parameters are optional according to the upstream docs, e.g. http://docs.telerik.com/kendo-ui/api/javascript/geometry/matrix#methods-toString * Ensure that zoneAbbr and zoneName are expected type (string). * Update moment-timezone.d.ts * Fix syntax error in interact.d.ts A parameter name was missing making TypeScript compiler fail. * adding type for move to fs-extra * fixing signature of sinon/alwaysReturned based on the http://sinonjs.org/docs/#sinonspy * increasing version number * returning back the version number to the origin number * reversing changes in fs-extra * Request that PRs have meaningful titles * Improvement to existing nouislider type definition. (#12033) * updated nouislider version and added a lot of tests out of the documentation * corrected intentation * corrected untyped variables, issue raised by Travis * incorporated feedback on pull request * #13037 (#13039) * #13037 * pointToLayer first argument type fixed GeoJSON.Point to GeoJSON.Feature<GeoJSON.Point> * Missing cc in sendgrid packate (#13063) The sendgrid package was missing the `cc` field, and the `bcc` field had a too generic type (`any` instead of `string[]`, as used on the `setCcs` and `setBccs` below. * Fixes #12414 (#13076) * Fixes #12414 * Make applicationServerKey optional * added ariaLabelledBy and ariaDescribedBy to IModalSettings (#13004) * Ceymard leaflet (#13007) * replaced all overrides of LatLng by a single use of LatLngExpression when appropriate * Changed Point, PointTuple overrides to use PointExpression instead * Changet use of LatLngBounds and Bounds in general to use the Expression variant instead of having several overrides * add ElasticSeach 5.x API function for deleteByQuery (#13014) * add ElasticSeach 5.x API function for deleteByQuery * use searchParams for deleteByQuery, as theses resemble the documentation. * add DeleteByQueryParams parameter type. * add deleteByQuery to tests. * Make `less` render options optional (#13078) * Added semver * Updated gravity definition. (#13088) * Full Redis client options (#13108) * Added missing return type to on() methods. (#13082) * Update react-native.0.29.d.ts (#13118) drawerPosition is of type `number` Android DrawerConsts.DrawerPosition.Left is equivalent to DrawerLayoutAndroid.positions.Left Android DrawerConsts.DrawerPosition.Right is equivalent to DrawerLayoutAndroid.positions.Right * Upgrade to match braintree-web 3.6.1 (#13098) * Update to match braintree-web version 3.3.0 * Upgrade to match Braintree-web v3.5.0 * upgrade to match braintree-web 3.6.1 add US bank class * Fix missing parameters from svg append (#13119) * Add parameter declarations to append() * Made insertFirst parameter optional * Correct missing ‘auto’ option of GridList’s cellHeight (#13094) * Add new Angular 1.5.9 methods to $compileProvider (#13096) * Add new Angular 1.5.9 methods to $compileProvider Add new methods available in Angular 1.5.9: onChangesTtl(), commentDirectivesEnabled() and cssClassDirectivesEnabled() * Add JSDoc to Angular 1.59 new methods of $compileProvider JSDoc for onChangesTtl(), commentDirectivesEnabled() and cssClassDirectivesEnabled() methods. * Expand $compileProvider JSDoc Urls added to JSDoc of Angular 1.5.9 new methods . * Changed type of injectedScript property to string (#13120) The injectedScript property should take string value with script code, not the bool flag as in current version * Use unions for openlayers string enums (#13134) * Update google.maps.MapPane interface (#13122) * Removing myself (AlStar01) as definition author from angular-material.d.ts (#13125) * Clarify that notNeededPackages.json is just for packages formerly on DefinitelyTyped (#13156) * Update Parsimmon typings (#13146) * Update AmCharts.d.ts (#13170) * knex: add MySqlConnectionConfig, tests (#13161) * knex: add MySqlConnectionConfig, tests * knex: add types for MySqlConnectionConfig queryFormat params * Add note in readme about tsjs-lib-generator (#13210) * Remove redux-localstorage packages; added by #13115 instead |
||
|---|---|---|
| .. | ||
| legacy | ||
| angular-component-router.d.ts | ||
| angular-tests.ts | ||
| index.d.ts | ||
| README.md | ||
| tsconfig.json | ||
AngularJS Definitions Usage Notes
Referencing AngularJS definition files in your code
To do that, simply add `` at the top of your code.
That will make available to your code all interfaces AngularJS' main module ng implements, as well as the AUTO module.
If you are including other AngularJS' modules in your code, like ngResource, just like you needed to include the additional module implementation file in your code, angular-resource.js, you will also need to reference the definitions file related to that module. Your code would then have the following definitions files reference:
Having these modules in separated files is actually good because they sometimes either augment or modify some of ng's interfaces, and thus those differences should only be available to you when you really need them. Also, it forces you to explicit what you're going to be using.
The following extra definition files are available for referencing:
- angular-resource.d.ts (for the ngResource module)
- angular-route.d.ts (for the ngRoute module)
- angular-cookies.d.ts (for the ngCookies module)
- angular-sanitize.d.ts (for the ngSanitize module)
- angular-animate.d.ts (for the ngAnimate module)
- angular-mocks.d.ts (for the ngMock and ngMockE2E modules)
(postfix with version number for specific verion, eg. angular-resource-1.0.d.ts)
The Angular Static
The definitions declare the AngularJS static variable angular as ambient. That means that, after referencing the AngularJS definition, you will be able to get type checks and code assistance for the global angular member.
Definitions modularized
To avoid cluttering the list of suggestions as you type in your IDE, all interfaces reside in their respective module namespace:
ngfor AngularJS' ng moduleng.autofor AUTOng.cookiesfor ngCookiesng.mockfor ngMockng.resourcefor ngResourceng.routefor ngRouteng.sanitizefor ngSanitizeng.animatefor ngAnimate
ngMockE2E does not define a new namespace, but rather modifies some of ng's interfaces.
Below is an example of how to use the interfaces:
function MainController($scope: ng.IScope, $http: ng.IHttpService) {
// code assistance will now be available for $scope and $http
}
Services and other injectables
AngularJS makes vast use of what it calls "injectable" functions. To put it simple, in AngularJS you are constantly annotating your functions and constructors with their dependencies, services that are going to be provided as arguments automagically during invocation.
All known services interfaces have been defined, and were named using the following convention:
I + 'ServiceName' + 'Service'
So, for instance, the $parse service has it's interface defined as ng.IParseService.
Service providers, by the same logic, follow this convention:
I + 'ServiceName' + 'Provider'
The $httpProvider, thus, is defined by ng.IHttpProvider.
A word on $scope and assigning new members
TypeScript allows for static checking. Among other obvious things, that means you're gonna have to extend interfaces when you need to augment an object whose interface has been defined, because otherwise the compiler will see it as an error to try to assign a value to a unspecified member.
Consider the following ordinary code:
function Controller($scope) {
$scope.$broadcast('myEvent');
$scope.title = 'Yabadabadu';
}
That will not produce any compilation error because the compiler does not know the first thing about $scope to do any checking. For that same reason, you will not get any assistance either.
Now consider this:
function Controller($scope: ng.IScope) {
$scope.$broadcast('myEvent');
$scope.title = 'Yabadabadu';
}
Now we annotated $scope with the interface ng.IScope. The compiler now knows that, among other members, $scope has a method called $broadcast. That interface, however, does not define a title property. The compiler will complain about it.
Since you are augmenting the $scope object, you should let the compiler know what to expect then:
interface ICustomScope extends ng.IScope {
title: string;
}
function Controller($scope: ICustomScope) {
$scope.$broadcast('myEvent');
$scope.title = 'Yabadabadu';
}
Examples
Working with $resource
// We have the option to define arguments for a custom resource
interface IArticleParameters {
id: number;
}
interface IArticleResource extends ng.resource.IResource<IArticleResource> {
title: string;
text: string;
date: Date;
author: number;
// Although all actions defined on IArticleResourceClass are avaiable with
// the '$' prefix, we have the choice to expose only what we will use
$publish(): IArticleResource;
$unpublish(): IArticleResource;
}
// Let's define a custom resource
interface IArticleResourceClass extends ng.resource.IResourceClass<IArticleResource> {
// Overload get to accept our custom parameters
get(): ng.resource.IResource;
get(params: IArticleParameters, onSuccess: Function): IArticleResource;
// Add our custom resource actions
publish(): IArticleResource;
publish(params: IArticleParameters): IArticleResource;
unpublish(params: IArticleParameters): IArticleResource;
}
function MainController($resource: ng.resource.IResourceService) {
// IntelliSense will provide IActionDescriptor interface and will validate
// your assignment against it
var publishDescriptor: ng.resource.IActionDescriptor;
publishDescriptor = {
method: 'GET',
isArray: false
};
// I could still create a descriptor without the interface...
var unpublishDescriptor = {
method: 'POST'
}
// A call to the $resource service returns a IResourceClass. Since
// our own IArticleResourceClass defines 2 more actions, we cast the return
// value to make the compiler aware of that
var articleResource = $resource<IArticleResource, IArticleResourceClass>('/articles/:id', null, {
publish : publishDescriptor,
unpublish : unpublishDescriptor
});
// Now we can do this
articleResource.unpublish({ id: 1 });
// IResourceClass.get() will be automatically available here
var article: IArticleResource = articleResource.get({id: 1}, function success() {
// Again, default + custom action here...
article.title = 'New Title';
article.$save();
article.$publish();
});
}
Working with $resource in angular-1.0 definitions
// Let's define a custom resource
interface IArticleResourceClass extends ng.resource.IResourceClass {
publish: ng.resource.IActionCall;
unpublish: ng.resource.IActionCall;
}
interface IArticleResource extends ng.resource.IResource {
title: string;
text: string;
date: Date;
author: number;
$publish: ng.resource.IActionCall;
$unpublish: ng.resource.IActionCall;
}
function MainController($resource: ng.resource.IResourceService) {
// IntelliSense will provide IActionDescriptor interface and will validate
// your assignment against it
var publishDescriptor: ng.resource.IActionDescriptor;
publishDescriptor = {
method: 'GET',
isArray: false
};
// I could still create a descriptor without the interface...
var unpublishDescriptor = {
method: 'POST'
}
// A call to the $resource service returns a IResourceClass. Since
// our own IArticleResourceClass defines 2 more actions, we cast the return
// value to make the compiler aware of that
var articles = <IArticleResourceClass> $resource('/articles/:id', null, {
publish : publishDescriptor,
unpublish : unpublishDescriptor
});
// Now we can do this
articles.unpublish({ id: 1 });
// IResourceClass.get() will be automatically available here
var article = <IArticleResource> articles.get({id: 1});
// Again, default + custom action here...
article.title = 'New Title';
article.$save();
article.$publish();
}