From 39044878194fad4ec48e9e9fc166a6feafca14f0 Mon Sep 17 00:00:00 2001 From: Chris Thielen Date: Sat, 30 Sep 2017 11:43:22 -0700 Subject: [PATCH] fix(redirectTo): Fix typings for redirectTo. Allow a function that returns a target state or a promise for one. --- src/state/interface.ts | 11 ++++++----- test/hooksSpec.ts | 4 ++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/state/interface.ts b/src/state/interface.ts index 6e2668d2..9aa98f53 100644 --- a/src/state/interface.ts +++ b/src/state/interface.ts @@ -54,7 +54,7 @@ export interface _ViewDeclaration { * @internalapi */ $uiViewName?: string; - + /** * The normalized context anchor (state name) for the `uiViewName` * @@ -314,13 +314,13 @@ export interface StateDeclaration { /** * Sets the resolve policy defaults for all resolves on this state * - * This should be an [[ResolvePolicy]] object. - * + * This should be an [[ResolvePolicy]] object. + * * It can contain the following optional keys/values: - * + * * - `when`: (optional) defines when the resolve is fetched. Accepted values: "LAZY" or "EAGER" * - `async`: (optional) if the transition waits for the resolve. Accepted values: "WAIT", "NOWAIT", "RXWAIT" - * + * * See [[ResolvePolicy]] for more details. */ resolvePolicy?: ResolvePolicy @@ -504,6 +504,7 @@ export interface StateDeclaration { * ``` */ redirectTo?: RedirectToResult | + ((transition: Transition) => RedirectToResult) | ((transition: Transition) => Promise); /** diff --git a/test/hooksSpec.ts b/test/hooksSpec.ts index feaed145..56f247f3 100644 --- a/test/hooksSpec.ts +++ b/test/hooksSpec.ts @@ -117,7 +117,7 @@ describe("hooks", () => { // Test for #3117 it("should not redirect if the redirectTo: function returns undefined", (done) => { - find(states, s => s.name === 'A').redirectTo = function() {}; + find(states, s => s.name === 'A').redirectTo = function() {} as any; init(); $state.go('A').then(() => { @@ -213,4 +213,4 @@ describe("hooks", () => { setTimeout(() => { router.dispose(); disposed(); }, 50); }); -}); \ No newline at end of file +});