UNPKG

angular2

Version:

Angular 2 - a web framework for modern web apps

150 lines (149 loc) 3.63 kB
import { ConcreteType, Type } from 'angular2/src/facade/lang'; /** * Declares the interface to be used with {@link Class}. */ export interface ClassDefinition { /** * Optional argument for specifying the superclass. */ extends?: Type; /** * Required constructor function for a class. * * The function may be optionally wrapped in an `Array`, in which case additional parameter * annotations may be specified. * The number of arguments and the number of parameter annotations must match. * * See {@link Class} for example of usage. */ constructor: Function | any[]; /** * Other methods on the class. Note that values should have type 'Function' but TS requires * all properties to have a narrower type than the index signature. */ [x: string]: Type | Function | any[]; } /** * An interface implemented by all Angular type decorators, which allows them to be used as ES7 * decorators as well as * Angular DSL syntax. * * DSL syntax: * * ``` * var MyClass = ng * .Component({...}) * .View({...}) * .Class({...}); * ``` * * ES7 syntax: * * ``` * @ng.Component({...}) * @ng.View({...}) * class MyClass {...} * ``` */ export interface TypeDecorator { /** * Invoke as ES7 decorator. */ <T extends Type>(type: T): T; (target: Object, propertyKey?: string | symbol, parameterIndex?: number): void; /** * Storage for the accumulated annotations so far used by the DSL syntax. * * Used by {@link Class} to annotate the generated class. */ annotations: any[]; /** * Generate a class from the definition and annotate it with {@link TypeDecorator#annotations}. */ Class(obj: ClassDefinition): ConcreteType; } /** * Provides a way for expressing ES6 classes with parameter annotations in ES5. * * ## Basic Example * * ``` * var Greeter = ng.Class({ * constructor: function(name) { * this.name = name; * }, * * greet: function() { * alert('Hello ' + this.name + '!'); * } * }); * ``` * * is equivalent to ES6: * * ``` * class Greeter { * constructor(name) { * this.name = name; * } * * greet() { * alert('Hello ' + this.name + '!'); * } * } * ``` * * or equivalent to ES5: * * ``` * var Greeter = function (name) { * this.name = name; * } * * Greeter.prototype.greet = function () { * alert('Hello ' + this.name + '!'); * } * ``` * * ### Example with parameter annotations * * ``` * var MyService = ng.Class({ * constructor: [String, [new Query(), QueryList], function(name, queryList) { * ... * }] * }); * ``` * * is equivalent to ES6: * * ``` * class MyService { * constructor(name: string, @Query() queryList: QueryList) { * ... * } * } * ``` * * ### Example with inheritance * * ``` * var Shape = ng.Class({ * constructor: (color) { * this.color = color; * } * }); * * var Square = ng.Class({ * extends: Shape, * constructor: function(color, size) { * Shape.call(this, color); * this.size = size; * } * }); * ``` */ export declare function Class(clsDef: ClassDefinition): ConcreteType; export declare function makeDecorator(annotationCls: any, chainFn?: (fn: Function) => void): (...args: any[]) => (cls: any) => any; export declare function makeParamDecorator(annotationCls: any): any; export declare function makePropDecorator(decoratorCls: any): any;