diff --git a/docs/dgeni-package/templates/angular2/angular2.d.ts.template.html b/docs/dgeni-package/templates/angular2/angular2.d.ts.template.html index 4be251c555..f902e923ce 100644 --- a/docs/dgeni-package/templates/angular2/angular2.d.ts.template.html +++ b/docs/dgeni-package/templates/angular2/angular2.d.ts.template.html @@ -9,11 +9,14 @@ interface List extends Array {} interface Map {} interface StringMap extends Map {} -interface Type {} +declare type Type = ng.Type; -declare module "angular2/angular2" { +declare module ng { type SetterFn = typeof Function; type int = number; + interface Type extends Function { + new (...args); + } // See https://github.com/Microsoft/TypeScript/issues/1168 class BaseException /* extends Error */ { @@ -22,4 +25,8 @@ declare module "angular2/angular2" { toString(): string; } } -{% endblock %} \ No newline at end of file +{% endblock %} + +declare module "angular2/angular2" { + export = ng; +} diff --git a/docs/dgeni-package/templates/type-definition.template.html b/docs/dgeni-package/templates/type-definition.template.html index aab6d138c4..6c0f2c0c64 100644 --- a/docs/dgeni-package/templates/type-definition.template.html +++ b/docs/dgeni-package/templates/type-definition.template.html @@ -32,7 +32,7 @@ {% block staticDeclarations %}{% endblock %} {% for alias, module in doc.moduleDocs %} {$ commentBlock(module.doc, 1) $} -declare module "{$ module.id $}" { +declare module ng { {%- for export in module.doc.exports -%} {%- if export.content -%} @@ -68,3 +68,6 @@ declare module "{$ module.id $}" { {% endfor %} +declare module "angular2/angular2" { + export = ng; +} diff --git a/modules/angular2/src/core/annotations/decorators.ts b/modules/angular2/src/core/annotations/decorators.ts index 363b9a12ee..e4c9a06d64 100644 --- a/modules/angular2/src/core/annotations/decorators.ts +++ b/modules/angular2/src/core/annotations/decorators.ts @@ -6,43 +6,56 @@ import { } from './annotations'; import {ViewAnnotation, ViewArgs} from './view'; import {AttributeAnnotation, QueryAnnotation} from './di'; -import {makeDecorator, makeParamDecorator, TypeDecorator, Class} from '../../util/decorators'; +import { + makeDecorator, + makeParamDecorator, + TypeDecorator, + ParamaterDecorator, + Class +} from '../../util/decorators'; import {Type} from 'angular2/src/facade/lang'; -export {ClassDefinition, TypeDecorator} from '../../util/decorators'; +export interface DirectiveDecorator extends TypeDecorator {} -export interface DirectiveTypeDecorator extends TypeDecorator {} +export interface ComponentDecorator extends TypeDecorator { View(obj: ViewArgs): ViewDecorator; } -export interface ComponentTypeDecorator extends TypeDecorator { - View(obj: ViewArgs): ViewTypeDecorator; -} +export interface ViewDecorator extends TypeDecorator { View(obj: ViewArgs): ViewDecorator } -export interface ViewTypeDecorator extends TypeDecorator { View(obj: ViewArgs): ViewTypeDecorator } - -export interface IDirective { - (obj: DirectiveArgs): DirectiveTypeDecorator; +export interface DirectiveFactory { + (obj: DirectiveArgs): DirectiveDecorator; new (obj: DirectiveAnnotation): DirectiveAnnotation; } -export interface IComponent { - (obj: ComponentArgs): ComponentTypeDecorator; +export interface ComponentFactory { + (obj: ComponentArgs): ComponentDecorator; new (obj: ComponentAnnotation): ComponentAnnotation; } -export interface IView { - (obj: ViewArgs): ViewTypeDecorator; +export interface ViewFactory { + (obj: ViewArgs): ViewDecorator; new (obj: ViewArgs): ViewAnnotation; } +export interface AttributeFactory { + (name: string): TypeDecorator; + new (name: string): AttributeAnnotation; +} + +export interface QueryFactory { + (selector: Type | string, {descendants}?: {descendants?: boolean}): ParameterDecorator; + new (selector: Type | string, {descendants}?: {descendants?: boolean}): QueryAnnotation; +} + /* from annotations */ -export var Component: IComponent = - makeDecorator(ComponentAnnotation, (fn: any) => fn.View = View); -export var Directive: IDirective = makeDecorator(DirectiveAnnotation); +export var Component: ComponentFactory = + makeDecorator(ComponentAnnotation, (fn: any) => fn.View = View); +export var Directive: DirectiveFactory = makeDecorator(DirectiveAnnotation); /* from view */ -export var View: IView = makeDecorator(ViewAnnotation, (fn: any) => fn.View = View); +export var View: ViewFactory = + makeDecorator(ViewAnnotation, (fn: any) => fn.View = View); /* from di */ -export var Attribute = makeParamDecorator(AttributeAnnotation); -export var Query = makeParamDecorator(QueryAnnotation); +export var Attribute: AttributeFactory = makeParamDecorator(AttributeAnnotation); +export var Query: QueryFactory = makeParamDecorator(QueryAnnotation); diff --git a/modules/angular2/src/util/decorators.ts b/modules/angular2/src/util/decorators.ts index 577fc5ff05..1fc2e2589c 100644 --- a/modules/angular2/src/util/decorators.ts +++ b/modules/angular2/src/util/decorators.ts @@ -6,11 +6,13 @@ export interface ClassDefinition { } export interface TypeDecorator { - (cls: any): any; + (cls: T): T; annotations: Array; Class(obj: ClassDefinition): Type; } +export interface ParamaterDecorator { (cls: Type, unusedKey: any, index: number): void } + function extractAnnotation(annotation: any): any { if (isFunction(annotation) && annotation.hasOwnProperty('annotation')) { // it is a decorator, extract annotation