Skip to content

Made ui-router noImplicitAny compliant #2836

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ module.exports = function (grunt) {
files: {
'<%= builddir %>/ui-router-ng2.min.js': ['<banner:meta.banner>', '<%= builddir %>/ui-router-ng2.js'],
'<%= builddir %>/angular-ui-router.min.js': ['<banner:meta.banner>', '<%= builddir %>/angular-ui-router.js'],
'<%= builddir %>/ng1/stateEvents.min.js': ['<banner:meta.banner>', '<%= builddir %>/ng1/stateEvents.js']
'<%= builddir %>/ng1/legacy/stateEvents.min.js': ['<banner:meta.banner>', '<%= builddir %>/ng1/legacy/stateEvents.js']
}
}
},
Expand Down Expand Up @@ -180,7 +180,7 @@ module.exports = function (grunt) {
grunt.task.run(['webpack']);

['stateEvents.js', 'stateEvents.js.map'].forEach(function(file) {
grunt.file.copy(builddir + "/es5/ng1/" + file, builddir + "/ng1/" + file);
grunt.file.copy(builddir + "/es5/ng1/legacy/" + file, builddir + "/ng1/legacy/" + file);
})
});

Expand Down
2 changes: 1 addition & 1 deletion files.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ routerFiles = {

src: [
'src/ng1.ts', // UI-Router angular1 module (re-exports ui-router and ng1 modules)
'src/ng1/stateEvents.ts' // There might be a better approach to compiling this file
'src/ng1/legacy/stateEvents.ts' // There might be a better approach to compiling this file
//'src/ui-router.ts', // Main UI-Router module (re-exports all other core modules)
//'src/ng2.ts', // UI-Router angular2 module (re-exports ui-router and ng2 modules)
//'src/justjs.ts', // UI-Router plain ol js module (re-exports ui-router)
Expand Down
106 changes: 53 additions & 53 deletions src/common/common.ts

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions src/common/coreservices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
//import {IQService} from "angular";
//import {IInjectorService} from "angular";

let notImplemented = (fnname) => () => {
let notImplemented = (fnname: any) => () => {
throw new Error(`${fnname}(): No coreservices implementation for UI-Router is loaded. You should include one of: ['angular1.js']`);
};

Expand All @@ -22,14 +22,14 @@ let services: CoreServices = {
};

["replace", "url", "path", "search", "hash", "onChange"]
.forEach(key => services.location[key] = notImplemented(key));
.forEach(key => (<any>services.location)[key] = notImplemented(key));

["port", "protocol", "host", "baseHref", "html5Mode", "hashPrefix" ]
.forEach(key => services.locationConfig[key] = notImplemented(key));
.forEach(key => (<any>services.locationConfig)[key] = notImplemented(key));

export interface CoreServices {
$q; // : IQService;
$injector; // : IInjectorService;
$q: any; // : IQService;
$injector: any; // : IInjectorService;
/** Services related to getting or setting the browser location (url) */
location: LocationServices;
/** Retrieves configuration for how to construct a URL. */
Expand Down
24 changes: 12 additions & 12 deletions src/common/hof.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export function curry(fn: Function): Function {
let initial_args = [].slice.apply(arguments, [1]);
let func_args_length = fn.length;

function curried(args) {
function curried(args: any) {
if (args.length >= func_args_length)
return fn.apply(null, args);
return function () {
Expand Down Expand Up @@ -121,22 +121,22 @@ export const parse = (name: string) => pipe.apply(null, name.split(".").map(prop
* Given a function that returns a truthy or falsey value, returns a
* function that returns the opposite (falsey or truthy) value given the same inputs
*/
export const not = (fn) => (...args) => !fn.apply(null, args);
export const not = (fn: any) => (...args: any[]) => !fn.apply(null, args);

/**
* Given two functions that return truthy or falsey values, returns a function that returns truthy
* if both functions return truthy for the given arguments
*/
export function and(fn1, fn2): Predicate<any> {
return (...args) => fn1.apply(null, args) && fn2.apply(null, args);
export function and(fn1: any, fn2: any): Predicate<any> {
return (...args: any[]) => fn1.apply(null, args) && fn2.apply(null, args);
}

/**
* Given two functions that return truthy or falsey values, returns a function that returns truthy
* if at least one of the functions returns truthy for the given arguments
*/
export function or(fn1, fn2): Predicate<any> {
return (...args) => fn1.apply(null, args) || fn2.apply(null, args);
export function or(fn1: any, fn2: any): Predicate<any> {
return (...args: any[]) => fn1.apply(null, args) || fn2.apply(null, args);
}

/**
Expand All @@ -145,16 +145,16 @@ export function or(fn1, fn2): Predicate<any> {
* @param fn1 a predicate function `fn1`
* @returns a function which takes an array and returns true if `fn1` is true for all elements of the array
*/
export const all = (fn1) => (arr: any[]) => arr.reduce((b, x) => b && !!fn1(x), true);
export const any = (fn1) => (arr: any[]) => arr.reduce((b, x) => b || !!fn1(x), false);
export const all = (fn1: any) => (arr: any[]) => arr.reduce((b, x) => b && !!fn1(x), true);
export const any = (fn1: any) => (arr: any[]) => arr.reduce((b, x) => b || !!fn1(x), false);
export const none: Function = not(any);

/** Given a class, returns a Predicate function that returns true if the object is of that class */
export const is: (ctor) => (x) => boolean =
export const is: (ctor: any) => (x: any) => boolean =
ctor => obj => (obj != null && obj.constructor === ctor || obj instanceof ctor);

/** Given a value, returns a Predicate function that returns true if another value is === equal to the original value */
export const eq: (comp) => (x) => boolean =
export const eq: (comp: any) => (x: any) => boolean =
(val) => (other) => val === other;

/** Given a value, returns a function which returns the value */
Expand All @@ -164,7 +164,7 @@ export const val = <T> (v: T) => () => v;

export function invoke(fnName: string): Function;
export function invoke(fnName: string, args: any[]): Function;
export function invoke(fnName: string, args?): Function {
export function invoke(fnName: string, args?: any): Function {
return (obj: any) => obj[fnName].apply(obj, args);
}

Expand Down Expand Up @@ -209,7 +209,7 @@ export function invoke(fnName: string, args?): Function {
* @returns {function(any): *}
*/
export function pattern(struct: Function[][]): Function {
return function(x) {
return function(x: any) {
for (var i = 0; i < struct.length; i++) {
if (struct[i][0](x)) return struct[i][1](x);
}
Expand Down
18 changes: 9 additions & 9 deletions src/common/predicates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@
import {and, not, pipe, prop} from "./hof";

const toStr = Object.prototype.toString;
const tis = (t) => (x) => typeof(x) === t;
const tis = (t: any) => (x: any) => typeof(x) === t;
export const isUndefined = tis('undefined');
export const isDefined = not(isUndefined);
export const isNull = o => o === null;
export const isFunction: (x) => x is Function = <any> tis('function');
export const isNumber: (x) => x is number = <any> tis('number');
export const isString = <(x) => x is string> tis('string');
export const isObject = (x) => x !== null && typeof x === 'object';
export const isNull = (o: any) => o === null;
export const isFunction: (x: any) => x is Function = <any> tis('function');
export const isNumber: (x: any) => x is number = <any> tis('number');
export const isString = <(x: any) => x is string> tis('string');
export const isObject = (x: any) => x !== null && typeof x === 'object';
export const isArray = Array.isArray;
export const isDate: (x) => x is Date = <any> ((x) => toStr.call(x) === '[object Date]');
export const isRegExp: (x) => x is RegExp = <any> ((x) => toStr.call(x) === '[object RegExp]');
export const isDate: (x: any) => x is Date = <any> ((x: any) => toStr.call(x) === '[object Date]');
export const isRegExp: (x: any) => x is RegExp = <any> ((x: any) => toStr.call(x) === '[object RegExp]');

/**
* Predicate which checks if a value is injectable
*
* A value is "injectable" if it is a function, or if it is an ng1 array-notation-style array
* where all the elements in the array are Strings, except the last one, which is a Function
*/
export function isInjectable(val) {
export function isInjectable(val: any) {
if (isArray(val) && val.length) {
let head = val.slice(0, -1), tail = val.slice(-1);
return !(head.filter(not(isString)).length || tail.filter(not(isFunction)).length);
Expand Down
4 changes: 2 additions & 2 deletions src/common/strings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ export function fnToString(fn: IInjectable) {
return _fn && _fn.toString() || "undefined";
}

let stringifyPatternFn = null;
let stringifyPattern = function(value) {
let stringifyPatternFn = null as any;
let stringifyPattern = function(value: any) {
let isTransitionRejectionPromise = Rejection.isTransitionRejectionPromise;

stringifyPatternFn = stringifyPatternFn || pattern([
Expand Down
20 changes: 10 additions & 10 deletions src/common/trace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import {PathNode} from "../path/node";
import {PolicyWhen} from "../resolve/interface";

/** @hidden */
function uiViewString (viewData) {
function uiViewString (viewData: any) {
if (!viewData) return 'ui-view (defunct)';
return `[ui-view#${viewData.id} tag ` +
`in template from '${viewData.creationContext && viewData.creationContext.name || '(root)'}' state]: ` +
Expand All @@ -53,7 +53,7 @@ const viewConfigString = (viewConfig: ViewConfig) =>

/** @hidden */
function normalizedCat(input: Category): string {
return isNumber(input) ? Category[input] : Category[Category[input]];
return isNumber(input) ? Category[input] : Category[Category[input] as any];
}


Expand Down Expand Up @@ -92,7 +92,7 @@ export class Trace {
if (!categories.length) {
categories = Object.keys(Category)
.filter(k => isNaN(parseInt(k, 10)))
.map(key => Category[key]);
.map(key => (<Category>(<any>Category[key as any])));
}
categories.map(normalizedCat).forEach(category => this._enabled[category] = enabled);
}
Expand Down Expand Up @@ -152,7 +152,7 @@ export class Trace {
}

/** called by ui-router code */
traceHookInvocation(step, options) {
traceHookInvocation(step: any, options: any) {
if (!this.enabled(Category.HOOK)) return;
let tid = parse("transition.$id")(options),
digest = this.approximateDigests,
Expand All @@ -163,7 +163,7 @@ export class Trace {
}

/** called by ui-router code */
traceHookResult(hookResult, transitionResult, transitionOptions) {
traceHookResult(hookResult: any, transitionResult: any, transitionOptions: any) {
if (!this.enabled(Category.HOOK)) return;
let tid = parse("transition.$id")(transitionOptions),
digest = this.approximateDigests,
Expand Down Expand Up @@ -192,7 +192,7 @@ export class Trace {
}

/** called by ui-router code */
traceError(error, trans: Transition) {
traceError(error: any, trans: Transition) {
if (!this.enabled(Category.TRANSITION)) return;
let tid = trans && trans.$id,
digest = this.approximateDigests,
Expand All @@ -201,7 +201,7 @@ export class Trace {
}

/** called by ui-router code */
traceSuccess(finalState, trans: Transition) {
traceSuccess(finalState: any, trans: Transition) {
if (!this.enabled(Category.TRANSITION)) return;
let tid = trans && trans.$id,
digest = this.approximateDigests,
Expand All @@ -217,19 +217,19 @@ export class Trace {
}

/** called by ui-router code */
traceUiViewConfigUpdated(viewData: ActiveUiView, context) {
traceUiViewConfigUpdated(viewData: ActiveUiView, context: any) {
if (!this.enabled(Category.UIVIEW)) return;
this.traceUiViewEvent("Updating", viewData, ` with ViewConfig from context='${context}'`);
}

/** called by ui-router code */
traceUiViewScopeCreated(viewData: ActiveUiView, newScope) {
traceUiViewScopeCreated(viewData: ActiveUiView, newScope: any) {
if (!this.enabled(Category.UIVIEW)) return;
this.traceUiViewEvent("Created scope for", viewData, `, scope #${newScope.$id}`);
}

/** called by ui-router code */
traceUiViewFill(viewData: ActiveUiView, html) {
traceUiViewFill(viewData: ActiveUiView, html: any) {
if (!this.enabled(Category.UIVIEW)) return;
this.traceUiViewEvent("Fill", viewData, ` with: ${maxLength(200, html)}`);
}
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/redirectTo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const redirectToHook = (transition: Transition, $injector: UIRInjector) =

return handleResult(redirect);

function handleResult(result) {
function handleResult(result: any) {
if (result instanceof TargetState) return result;
if (isString(result)) return $state.target(<any> result, transition.params(), transition.options());
if (result['state'] || result['params'])
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/resolve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ export const $eagerResolvePath = (trans: Transition) =>
new ResolveContext(trans.treeChanges().to).resolvePath("EAGER", trans).then(noop);

/** A function which resolves all LAZY Resolvables for the state (and all ancestors) in the To Path */
export const $lazyResolveState = (trans: Transition, injector, state: State) =>
export const $lazyResolveState = (trans: Transition, injector: any, state: State) =>
new ResolveContext(trans.treeChanges().to).subContext(state).resolvePath("LAZY", trans).then(noop);

4 changes: 2 additions & 2 deletions src/hooks/views.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import {UiRouter} from "../router";


/** Allows the views to do async work [.load()] before the transition continues */
export function loadEnteringViews(transition) {
export function loadEnteringViews(transition: any) {
let enteringViews = transition.views("entering");
if (!enteringViews.length) return;
return services.$q.all(enteringViews.map(view => view.load())).then(noop);
return services.$q.all(enteringViews.map((view: any) => view.load())).then(noop);
}

export function activateViews(transition: Transition, injector: UIRInjector) {
Expand Down
30 changes: 15 additions & 15 deletions src/justjs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import {isFunction, isArray, isObject, isInjectable} from "./common/predicates";
import {extend, assertPredicate} from "./common/common";

/** $q-like promise api */
services.$q = (executor: (resolve, reject) => void) => new Promise(executor);
services.$q.when = (val) => Promise.resolve(val);
services.$q.reject = (val) => Promise.reject(val);
services.$q = (executor: (resolve: any, reject: any) => void) => new Promise(executor);
services.$q.when = (val: any) => Promise.resolve(val);
services.$q.reject = (val: any) => Promise.reject(val);
services.$q.defer = function() {
let deferred: any = {};
deferred.promise = new Promise((resolve, reject) => {
Expand All @@ -32,10 +32,10 @@ services.$q.all = function (promises: { [key: string]: Promise<any> } | Promise<
// Convert promises map to promises array.
// When each promise resolves, map it to a tuple { key: key, val: val }
let objectToTuples = Object.keys(promises)
.map(key => promises[key].then(val => ({key, val})));
.map(key => (<any>promises)[key].then((val: any) => ({key, val})));

const tuplesToObject = values =>
values.reduce((acc, tuple) => { acc[tuple.key] = tuple.val; return acc; }, {});
const tuplesToObject = (values: any) =>
values.reduce((acc: any, tuple: any) => { acc[tuple.key] = tuple.val; return acc; }, {});

// Then wait for all promises to resolve, and convert them back to an object
return services.$q.all(objectToTuples).then(tuplesToObject);
Expand All @@ -49,24 +49,24 @@ services.$q.all = function (promises: { [key: string]: Promise<any> } | Promise<
// angular1-like injector api

// globally available injectables
let globals = { };
let globals: { [key: string]: any; } = { };
services.$injector = { };

services.$injector.get = name => globals[name];
services.$injector.has = (name) => services.$injector.get(name) != null;
services.$injector.invoke = function(fn, context?, locals?) {
services.$injector.get = (name: any) => globals[name];
services.$injector.has = (name: any) => services.$injector.get(name) != null;
services.$injector.invoke = function(fn: any, context?: any, locals?: any) {
let all = extend({}, globals, locals || {});
let params = services.$injector.annotate(fn);
let ensureExist = assertPredicate(key => all.hasOwnProperty(key), key => `Could not find Dependency Injection token: ${stringify(key)}`);
let args = params.filter(ensureExist).map(x => all[x]);
let ensureExist = assertPredicate(key => all.hasOwnProperty(key), (key: any) => `Could not find Dependency Injection token: ${stringify(key)}`);
let args = params.filter(ensureExist).map((x: any) => all[x]);
if (isFunction(fn)) return fn.apply(context, args);
return fn.slice(-1)[0].apply(context, args);
};

let STRIP_COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg;
let ARGUMENT_NAMES = /([^\s,]+)/g;
// http://stackoverflow.com/questions/1007981
services.$injector.annotate = function(fn) {
services.$injector.annotate = function(fn: any) {
if (!isInjectable(fn)) throw new Error(`Not an injectable function: ${fn}`);
if (fn && fn.$inject) return fn.$inject;
if (isArray(fn)) return fn.slice(0, -1);
Expand All @@ -80,9 +80,9 @@ let loc = <any> services.location;
loc.hash = () => "";
loc.path = () => location.hash.replace(/^#/, "");
loc.search = () => location.search;
loc.url = (url) => { if (url) location.hash = url; return loc.path(); };
loc.url = (url: any) => { if (url) location.hash = url; return loc.path(); };
loc.replace = () => { console.log(new Error("not impl")); };
loc.onChange = (cb) => {
loc.onChange = (cb: any) => {
window.addEventListener("hashchange", cb, false);
};

Expand Down
Loading