chore: improve angular2.d.ts file

- support ambient and import format for .d.ts
This commit is contained in:
Misko Hevery 2015-07-02 22:26:07 +02:00 committed by Alex Eagle
parent 65a767d9b0
commit 0052c6b120
4 changed files with 50 additions and 25 deletions

View File

@ -9,11 +9,14 @@
interface List<T> extends Array<T> {}
interface Map<K,V> {}
interface StringMap<K,V> extends Map<K,V> {}
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 %}
{% endblock %}
declare module "angular2/angular2" {
export = ng;
}

View File

@ -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;
}

View File

@ -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 =
<IComponent>makeDecorator(ComponentAnnotation, (fn: any) => fn.View = View);
export var Directive: IDirective = <IDirective>makeDecorator(DirectiveAnnotation);
export var Component: ComponentFactory =
<ComponentFactory>makeDecorator(ComponentAnnotation, (fn: any) => fn.View = View);
export var Directive: DirectiveFactory = <DirectiveFactory>makeDecorator(DirectiveAnnotation);
/* from view */
export var View: IView = <IView>makeDecorator(ViewAnnotation, (fn: any) => fn.View = View);
export var View: ViewFactory =
<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);

View File

@ -6,11 +6,13 @@ export interface ClassDefinition {
}
export interface TypeDecorator {
(cls: any): any;
<T>(cls: T): T;
annotations: Array<any>;
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