Skip to content

Commit

Permalink
feat(typescript): Add typescript definitions for component builds
Browse files Browse the repository at this point in the history
- Add api/angular-ui-router,d.ts typescript definition file
- Add reference to typescript definition in component.json

Simplifies usage of this library by typescript developers (+2 squashed commits)
Squashed commits:
[531f0b8] remove angular reference
[268643f] added typescript definition for component builds
  • Loading branch information
Frank Wallis authored and frankwallis committed Aug 20, 2014
1 parent 8aed5da commit 521ceb3
Show file tree
Hide file tree
Showing 2 changed files with 144 additions and 0 deletions.
138 changes: 138 additions & 0 deletions api/angular-ui-router.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
// Type definitions for Angular JS 1.1.5+ (ui.router module)
// Project: https://github.com/angular-ui/ui-router
// Definitions by: Michel Salib <https://github.com/michelsalib>
// Definitions: https://github.com/borisyankov/DefinitelyTyped

declare module ng.ui {

interface IState {
name?: string;
template?: string;
templateUrl?: any; // string || () => string
templateProvider?: any; // () => string || IPromise<string>
controller?: any;
controllerAs?: string;
controllerProvider?: any;
resolve?: {};
url?: string;
params?: any[];
views?: {};
abstract?: boolean;
onEnter?: (...args: any[]) => void;
onExit?: (...args: any[]) => void;
data?: any;
}

interface ITypedState<T> {
name?: string;
template?: string;
templateUrl?: string;
templateProvider?: () => string;
controller?: any;
controllerAs?: string;
controllerProvider?: any;
resolve?: {};
url?: string;
params?: any[];
views?: {};
abstract?: boolean;
onEnter?: (...args: any[]) => void;
onExit?: (...args: any[]) => void;
data?: T;
}

interface IStateProvider extends IServiceProvider {
state(name: string, config: IState): IStateProvider;
state(config: IState): IStateProvider;
decorator(name?: string, decorator?: (state: IState, parent: Function) => any): any;
}

interface IUrlMatcher {
concat(pattern: string): IUrlMatcher;
exec(path: string, searchParams: {}): {};
parameters(): string[];
format(values: {}): string;
}

interface IUrlMatcherFactory {
compile(pattern: string): IUrlMatcher;
isMatcher(o: any): boolean;
}

interface IUrlRouterProvider extends IServiceProvider {
when(whenPath: RegExp, handler: Function): IUrlRouterProvider;
when(whenPath: RegExp, handler: any[]): IUrlRouterProvider;
when(whenPath: RegExp, toPath: string): IUrlRouterProvider;
when(whenPath: IUrlMatcher, hanlder: Function): IUrlRouterProvider;
when(whenPath: IUrlMatcher, handler: any[]): IUrlRouterProvider;
when(whenPath: IUrlMatcher, toPath: string): IUrlRouterProvider;
when(whenPath: string, handler: Function): IUrlRouterProvider;
when(whenPath: string, handler: any[]): IUrlRouterProvider;
when(whenPath: string, toPath: string): IUrlRouterProvider;
otherwise(handler: Function): IUrlRouterProvider;
otherwise(handler: any[]): IUrlRouterProvider;
otherwise(path: string): IUrlRouterProvider;
rule(handler: Function): IUrlRouterProvider;
rule(handler: any[]): IUrlRouterProvider;
}

interface IStateOptions {
location?: any;
inherit?: boolean;
relative?: IState;
notify?: boolean;
}

interface IHrefOptions {
lossy?: boolean;
inherit?: boolean;
relative?: IState;
absolute?: boolean;
}

interface IStateService {
go(to: string, params?: {}, options?: IStateOptions): IPromise<any>;
transitionTo(state: string, params?: {}, updateLocation?: boolean): void;
transitionTo(state: string, params?: {}, options?: IStateOptions): void;
includes(state: string, params?: {}): boolean;
is(state:string, params?: {}): boolean;
is(state: IState, params?: {}): boolean;
href(state: IState, params?: {}, options?: IHrefOptions): string;
href(state: string, params?: {}, options?: IHrefOptions): string;
get(state: string): IState;
get(): IState[];
current: IState;
params: any;
reload(): void;
}

interface IStateParamsService {
[key: string]: any;
}

interface IStateParams {
[key: string]: any;
}

interface IUrlRouterService {
/*
* Triggers an update; the same update that happens when the address bar
* url changes, aka $locationChangeSuccess.
*
* This method is useful when you need to use preventDefault() on the
* $locationChangeSuccess event, perform some custom logic (route protection,
* auth, config, redirection, etc) and then finally proceed with the transition
* by calling $urlRouter.sync().
*
*/
sync(): void;
}

interface IUiViewScrollProvider {
/*
* Reverts back to using the core $anchorScroll service for scrolling
* based on the url anchor.
*/
useAnchorScroll(): void;
}
}
6 changes: 6 additions & 0 deletions component.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,15 @@
"routing"
],
"main": "release/angular-ui-router.min.js",
"typescript": {
"definition": "api/angular-ui-router.d.ts"
},
"scripts": [
"release/angular-ui-router.min.js"
],
"files": [
"api/angular-ui-router.d.ts"
],
"license": "MIT",
"repo": "angular-ui/ui-router"
}

0 comments on commit 521ceb3

Please sign in to comment.