Skip to content

Commit 3904487

Browse files
fix(redirectTo): Fix typings for redirectTo. Allow a function that returns a target state or a promise for one.
1 parent bf97873 commit 3904487

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

src/state/interface.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export interface _ViewDeclaration {
5454
* @internalapi
5555
*/
5656
$uiViewName?: string;
57-
57+
5858
/**
5959
* The normalized context anchor (state name) for the `uiViewName`
6060
*
@@ -314,13 +314,13 @@ export interface StateDeclaration {
314314
/**
315315
* Sets the resolve policy defaults for all resolves on this state
316316
*
317-
* This should be an [[ResolvePolicy]] object.
318-
*
317+
* This should be an [[ResolvePolicy]] object.
318+
*
319319
* It can contain the following optional keys/values:
320-
*
320+
*
321321
* - `when`: (optional) defines when the resolve is fetched. Accepted values: "LAZY" or "EAGER"
322322
* - `async`: (optional) if the transition waits for the resolve. Accepted values: "WAIT", "NOWAIT", "RXWAIT"
323-
*
323+
*
324324
* See [[ResolvePolicy]] for more details.
325325
*/
326326
resolvePolicy?: ResolvePolicy
@@ -504,6 +504,7 @@ export interface StateDeclaration {
504504
* ```
505505
*/
506506
redirectTo?: RedirectToResult |
507+
((transition: Transition) => RedirectToResult) |
507508
((transition: Transition) => Promise<RedirectToResult>);
508509

509510
/**

test/hooksSpec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ describe("hooks", () => {
117117

118118
// Test for #3117
119119
it("should not redirect if the redirectTo: function returns undefined", (done) => {
120-
find(states, s => s.name === 'A').redirectTo = function() {};
120+
find(states, s => s.name === 'A').redirectTo = function() {} as any;
121121
init();
122122

123123
$state.go('A').then(() => {
@@ -213,4 +213,4 @@ describe("hooks", () => {
213213

214214
setTimeout(() => { router.dispose(); disposed(); }, 50);
215215
});
216-
});
216+
});

0 commit comments

Comments
 (0)