Skip to content

Commit

Permalink
fix(redirectTo): Fix typings for redirectTo. Allow a function that re…
Browse files Browse the repository at this point in the history
…turns a target state or a promise for one.
  • Loading branch information
christopherthielen committed Sep 30, 2017
1 parent bf97873 commit 3904487
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
11 changes: 6 additions & 5 deletions src/state/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export interface _ViewDeclaration {
* @internalapi
*/
$uiViewName?: string;

/**
* The normalized context anchor (state name) for the `uiViewName`
*
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -504,6 +504,7 @@ export interface StateDeclaration {
* ```
*/
redirectTo?: RedirectToResult |
((transition: Transition) => RedirectToResult) |
((transition: Transition) => Promise<RedirectToResult>);

/**
Expand Down
4 changes: 2 additions & 2 deletions test/hooksSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down Expand Up @@ -213,4 +213,4 @@ describe("hooks", () => {

setTimeout(() => { router.dispose(); disposed(); }, 50);
});
});
});

0 comments on commit 3904487

Please sign in to comment.