Skip to content

Commit 5d40c91

Browse files
committed
Type improvements on url service
1 parent 26795f9 commit 5d40c91

22 files changed

Lines changed: 349 additions & 147 deletions

@types/namespace.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ import {
130130
import { AnimateRunner as TAnimateRunner } from "./animations/runner/animate-runner.js";
131131
import { Transition as TTransition } from "./router/transition/transition.js";
132132
import { TemplateFactoryProvider as TTemplateFactoryProvider } from "./router/template-factory.js";
133+
import { TransitionProviderService as TTransitionProviderService } from "./router/transition/interface.ts";
133134
declare global {
134135
interface Function {
135136
$inject?: readonly string[] | undefined;
@@ -166,6 +167,7 @@ declare global {
166167
type SceProvider = TSceProvider;
167168
type SceDelegateProvider = TSceDelegateProvider;
168169
type TransitionProvider = TTransitionProvider;
170+
type TransitionProviderService = TTransitionProviderService;
169171
type RouterProvider = TRouterProvider;
170172
type TemplateFactoryProvider = TTemplateFactoryProvider;
171173
type AnchorScrollService = TAnchorScrollService;

@types/router/hooks/url.d.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.

@types/router/state/state-queue-manager.d.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ export class StateQueueManager {
2323
* @type {Array<StateObject>}
2424
*/
2525
queue: Array<StateObject>;
26-
register(stateDecl: any): StateObject;
26+
/**
27+
* @param {ng.StateDeclaration} stateDecl
28+
* @returns {StateObject}
29+
*/
30+
register(stateDecl: ng.StateDeclaration): StateObject;
2731
flush(): import("./interface.ts").StateStore;
2832
/**
2933
*

@types/router/state/state-service.d.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,10 @@ export class StateProvider {
2525
get params(): import("../params/state-params.js").StateParams;
2626
/**
2727
* The current [[StateDeclaration]]
28-
*
29-
* @deprecated This is a passthrough through to [[Router.current]]
3028
*/
3129
get current(): import("./interface.ts").StateDeclaration;
3230
/**
3331
* The current [[StateObject]] (an internal API)
34-
*
35-
* @deprecated This is a passthrough through to [[Router.$current]]
3632
*/
3733
get $current(): import("./state-object.js").StateObject;
3834
/**

@types/router/transition/interface.d.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -834,3 +834,61 @@ export interface IMatchingNodes {
834834
* Or, `true` to always match
835835
*/
836836
export type HookMatchCriterion = string | IStateMatch | boolean;
837+
/**
838+
* The runtime service instance returned from `TransitionProvider.$get`.
839+
*
840+
* Note: In this codebase, `$get` returns the provider instance (`return this;`),
841+
* so the "service" surface includes both the public HookRegistry API and
842+
* a set of internal fields/methods used by built-in hook registrations/plugins.
843+
*/
844+
export interface TransitionProviderService {
845+
onBefore(
846+
matchCriteria: HookMatchCriteria,
847+
callback: (transition: Transition) => any,
848+
options?: HookRegOptions,
849+
): Function;
850+
onStart(
851+
matchCriteria: HookMatchCriteria,
852+
callback: (transition: Transition) => any,
853+
options?: HookRegOptions,
854+
): Function;
855+
onFinish(
856+
matchCriteria: HookMatchCriteria,
857+
callback: (transition: Transition) => any,
858+
options?: HookRegOptions,
859+
): Function;
860+
onSuccess(
861+
matchCriteria: HookMatchCriteria,
862+
callback: (transition: Transition) => any,
863+
options?: HookRegOptions,
864+
): Function;
865+
onError(
866+
matchCriteria: HookMatchCriteria,
867+
callback: (transition: Transition) => any,
868+
options?: HookRegOptions,
869+
): Function;
870+
onEnter(
871+
matchCriteria: HookMatchCriteria,
872+
callback: (...injectables: any[]) => any,
873+
options?: HookRegOptions,
874+
): Function;
875+
onRetain(
876+
matchCriteria: HookMatchCriteria,
877+
callback: (...injectables: any[]) => any,
878+
options?: HookRegOptions,
879+
): Function;
880+
onExit(
881+
matchCriteria: HookMatchCriteria,
882+
callback: (...injectables: any[]) => any,
883+
options?: HookRegOptions,
884+
): Function;
885+
/**
886+
* Returns the registered hooks for a hook name.
887+
* (This is also part of the HookRegistry interface in your types.)
888+
*/
889+
getHooks(hookName: string): RegisteredHook[];
890+
/**
891+
* Internal factory used by StateService.
892+
*/
893+
create(fromPath: PathNode[], targetState: TargetState): Transition;
894+
}

@types/router/transition/transition-service.d.ts

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
export namespace defaultTransOpts {
2-
let location: boolean;
3-
let relative: any;
4-
let inherit: boolean;
5-
let notify: boolean;
6-
let reload: boolean;
7-
let supercede: boolean;
8-
let custom: {};
9-
function current(): any;
10-
let source: string;
11-
}
1+
/**
2+
* The default [[Transition]] options.
3+
*
4+
* Include this object when applying custom defaults:
5+
* let reloadOpts = { reload: true, notify: true }
6+
* let options = defaults(theirOpts, customDefaults, defaultOptions);
7+
* @type {import("./interface.js").TransitionOptions}
8+
*/
9+
export const defaultTransOpts: import("./interface.js").TransitionOptions;
1210
/**
1311
* This class provides services related to Transitions.
1412
*
@@ -47,11 +45,11 @@ export class TransitionProvider {
4745
$get: (
4846
| string
4947
| ((
50-
stateService: any,
51-
urlService: any,
52-
stateRegistry: any,
53-
viewService: any,
54-
) => this)
48+
stateService: ng.StateService,
49+
urlService: ng.UrlService,
50+
stateRegistry: ng.StateRegistryService,
51+
viewService: ng.ViewService,
52+
) => ng.TransitionProviderService)
5553
)[];
5654
/**
5755
* Registers a [[TransitionHookFn]], called *while a transition is being constructed*.
@@ -90,10 +88,16 @@ export class TransitionProvider {
9088
create(fromPath: any, targetState: any): Transition;
9189
_defineCoreEvents(): void;
9290
_defineCorePaths(): void;
91+
/**
92+
* @param {string} name
93+
* @param {number} hookPhase
94+
* @param {number} hookOrder
95+
* @param {any} criteriaMatchPath
96+
*/
9397
_defineEvent(
94-
name: any,
95-
hookPhase: any,
96-
hookOrder: any,
98+
name: string,
99+
hookPhase: number,
100+
hookOrder: number,
97101
criteriaMatchPath: any,
98102
reverseSort?: boolean,
99103
getResultHandler?: (hook: any) => (result: any) => any,
@@ -115,10 +119,11 @@ export class TransitionProvider {
115119
* Another example: the `to` path in [[HookMatchCriteria]] is a TRANSITION scoped path.
116120
* It was defined by calling `defineTreeChangesCriterion('to', TransitionHookScope.TRANSITION)`
117121
* Only the tail of the `to` path is checked against the criteria and returned as part of the match.
118-
*
119122
* @internal
123+
* @param {string} name
124+
* @param {number} hookScope
120125
*/
121-
_definePathType(name: any, hookScope: any): void;
126+
_definePathType(name: string, hookScope: number): void;
122127
_getPathTypes(): {};
123128
getHooks(hookName: any): any;
124129
_registerCoreTransitionHooks(): void;

@types/router/transition/transition.d.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,6 @@ export class Transition {
4949
_options: any;
5050
$id: number;
5151
_treeChanges: import("./interface.ts").TreeChanges;
52-
onStart: any;
53-
onBefore: any;
54-
onSuccess: any;
55-
onEnter: any;
56-
onRetain: any;
57-
onExit: any;
58-
onFinish: any;
59-
onError: any;
6052
/**
6153
* Creates the transition-level hook registration functions
6254
* (which can then be used to register hooks)

@types/router/url/url-rule.d.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ export class UrlRuleFactory {
1717
routerGlobals: ng.RouterService;
1818
/**
1919
*
20-
* @param {*} what
21-
* @param {*} handler
20+
* @param {StateObject} what
21+
* @param {*} [handler]
2222
* @returns {BaseUrlRule}
2323
*/
24-
create(what: any, handler: any): BaseUrlRule;
24+
create(what: StateObject, handler?: any): BaseUrlRule;
2525
/**
2626
* A UrlRule which matches based on a UrlMatcher
2727
*
@@ -152,3 +152,4 @@ export class BaseUrlRule {
152152
*/
153153
matchPriority(params?: any): number;
154154
}
155+
import { StateObject } from "../state/state-object.js";

@types/router/url/url-service.d.ts

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,15 @@ export class UrlService {
1515
globals: import("../router.js").RouterProvider,
1616
urlConfigProvider: import("../../router/url/url-config.js").UrlConfigProvider,
1717
);
18-
/** @type {ng.LocationService} */
19-
$location: ng.LocationService;
18+
/** @type {ng.LocationService | undefined} */
19+
$location: ng.LocationService | undefined;
2020
/** @private */
2121
private _locationProvider;
2222
stateService: import("../../router/state/state-service.js").StateProvider;
23-
/** @type {UrlRuleFactory} Provides services related to the URL */
23+
/**
24+
* @type {UrlRuleFactory} Provides services related to the URL
25+
* @ignore
26+
*/
2427
_urlRuleFactory: UrlRuleFactory;
2528
/**
2629
* The nested [[UrlRules]] API for managing URL rules and rewrites
@@ -30,12 +33,20 @@ export class UrlService {
3033
_rules: UrlRules;
3134
/**
3235
* The nested [[UrlConfig]] API to configure the URL and retrieve URL information
36+
* @ignore
3337
* @type {import("./url-config.js").UrlConfigProvider}
3438
*/
3539
_config: import("./url-config.js").UrlConfigProvider;
36-
/** @type {ParamFactory} Creates a new [[Param]] for a given location (DefType) */
40+
/**
41+
* @type {ParamFactory} Creates a new [[Param]] for a given location (DefType)
42+
* @ignore
43+
*/
3744
_paramFactory: ParamFactory;
38-
_urlListeners: any[];
45+
/**
46+
* @type {((evt: ng.ScopeEvent) => void)[]}
47+
* @ignore
48+
*/
49+
_urlListeners: ((evt: ng.ScopeEvent) => void)[];
3950
/**
4051
* Gets the path part of the current url
4152
*
@@ -136,8 +147,8 @@ export class UrlService {
136147
* let deregisterFn = locationServices.onChange((evt) => console.log("url change", evt));
137148
* ```
138149
*
139-
* @param {Function} callback a function that will be called when the url is changing
140-
* @return {Function} a function that de-registers the callback
150+
* @param {(evt: ng.ScopeEvent) => void} callback a function that will be called when the url is changing
151+
* @return {() => void} a function that de-registers the callback
141152
*/
142153
private onChange;
143154
/**
@@ -236,19 +247,19 @@ export class UrlService {
236247
/**
237248
* Creates a [[UrlMatcher]] for the specified pattern.
238249
*
239-
* @param urlPattern The URL pattern.
240-
* @param config The config object hash.
250+
* @param {string} urlPattern The URL pattern.
251+
* @param {*} [config] The config object hash.
241252
* @returns The UrlMatcher.
242253
*/
243-
compile(urlPattern: any, config: any): UrlMatcher;
254+
compile(urlPattern: string, config?: any): UrlMatcher;
244255
/**
245256
* Returns true if the specified object is a [[UrlMatcher]], or false otherwise.
246257
*
247-
* @param object The object to perform the type check against.
258+
* @param {UrlMatcher & Record<string, any>} object The object to perform the type check against.
248259
* @returns `true` if the object matches the `UrlMatcher` interface, by
249260
* implementing all the same methods.
250261
*/
251-
isMatcher(object: any): boolean;
262+
isMatcher(object: UrlMatcher & Record<string, any>): boolean;
252263
}
253264
import { UrlRuleFactory } from "./url-rule.js";
254265
import { UrlRules } from "./url-rules.js";

@types/services/location/interface.d.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,7 @@ export interface UrlParts {
5252
* The parsed query string as an object.
5353
* Mirrors AngularJS’s `$location.setSearch()` format.
5454
*/
55-
search: Record<
56-
string,
57-
string | number | boolean | (string | number | boolean)[]
58-
>;
55+
search: Object;
5956
/**
6057
* The fragment identifier (everything after `#`, not including the `#` itself).
6158
*/

0 commit comments

Comments
 (0)