Skip to content

Commit f28f0e1

Browse files
committed
Type improvements
1 parent 5fc4611 commit f28f0e1

15 files changed

+92
-50
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ import {
1414
} from "../resolve/interface.ts";
1515
import { Resolvable } from "../resolve/resolvable.js";
1616
import { TargetState } from "./target-state.js";
17+
import { Glob } from "../glob/glob.js";
1718
export type StateOrName = string | StateDeclaration | StateObject;
19+
export type StateStore = Record<string, StateObject | BuiltStateDeclaration>;
1820
export interface TransitionPromise extends Promise<StateObject> {
1921
transition: Transition;
2022
}
@@ -826,6 +828,9 @@ export type BuiltStateDeclaration = StateDeclaration & {
826828
parent?: BuiltStateDeclaration | null;
827829
/** Optional inherited data */
828830
data?: any;
831+
_stateObjectCache?: {
832+
nameGlob: Glob;
833+
} | null;
829834
};
830835
/**
831836
* The return type of a [[StateDeclaration.lazyLoad]] function

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,22 @@ export function resolvablesBuilder(
5858
export class StateBuilder {
5959
/**
6060
* @param {import('./state-matcher.js').StateMatcher} matcher
61-
* @param urlService
61+
* @param {ng.UrlService} urlService
6262
*/
6363
constructor(
6464
matcher: import("./state-matcher.js").StateMatcher,
65-
urlService: any,
65+
urlService: ng.UrlService,
6666
);
6767
matcher: import("./state-matcher.js").StateMatcher;
6868
$injector: any;
6969
builders: {
7070
name: ((state: any) => any)[];
7171
self: (typeof selfBuilder)[];
72-
parent: ((state: any) => any)[];
72+
parent: ((
73+
state: any,
74+
) =>
75+
| import("./state-object.js").StateObject
76+
| import("./interface.ts").BuiltStateDeclaration)[];
7377
data: (typeof dataBuilder)[];
7478
url: ((stateObject: any) => any)[];
7579
navigable: ((state: any) => any)[];
Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
export class StateMatcher {
2-
constructor(_states: any);
3-
_states: any;
2+
/** @param {import("./interface.ts").StateStore} states */
3+
constructor(states: import("./interface.ts").StateStore);
4+
/** @type {import("./interface.ts").StateStore} */
5+
_states: import("./interface.ts").StateStore;
46
isRelative(stateName: any): boolean;
5-
find(stateOrName: any, base: any, matchGlob?: boolean): any;
7+
find(
8+
stateOrName: any,
9+
base: any,
10+
matchGlob?: boolean,
11+
):
12+
| import("./state-object.js").StateObject
13+
| import("./interface.ts").BuiltStateDeclaration;
614
resolvePath(name: any, base: any): string;
715
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export class StateObject implements ng.StateDeclaration {
2626
* @type {ng.StateDeclaration|ng.BuiltStateDeclaration}
2727
*/
2828
self: ng.StateDeclaration | ng.BuiltStateDeclaration;
29-
__stateObjectCache: {
29+
_stateObjectCache: {
3030
nameGlob: Glob;
3131
};
3232
/**

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,29 @@ export class StateQueueManager {
22
/**
33
* @param {import("./state-registry.js").StateRegistryProvider} stateRegistry
44
* @param {import("../url/url-rules.js").UrlRules} urlServiceRules
5-
* @param {Record<string, ng.StateObject>} states
5+
* @param {import("./interface.js").StateStore} states
66
* @param {*} builder
77
* @param {*} listeners
88
*/
99
constructor(
1010
stateRegistry: import("./state-registry.js").StateRegistryProvider,
1111
urlServiceRules: import("../url/url-rules.js").UrlRules,
12-
states: Record<string, ng.StateObject>,
12+
states: import("./interface.js").StateStore,
1313
builder: any,
1414
listeners: any,
1515
);
1616
stateRegistry: import("./state-registry.js").StateRegistryProvider;
1717
/** @type {import("../url/url-rules.js").UrlRules} */
1818
urlServiceRules: import("../url/url-rules.js").UrlRules;
19-
states: Record<string, StateObject>;
19+
states: import("./interface.js").StateStore;
2020
builder: any;
2121
listeners: any;
2222
/**
2323
* @type {Array<StateObject>}
2424
*/
2525
queue: Array<StateObject>;
2626
register(stateDecl: any): StateObject;
27-
flush(): Record<string, StateObject>;
27+
flush(): import("./interface.js").StateStore;
2828
/**
2929
*
3030
* @param {ng.StateDeclaration} state

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ export class StateRegistryProvider {
1919
globals: ng.RouterService,
2020
viewService: ng.ViewService,
2121
);
22-
/** @type {Record<string, import("./state-object.js").StateObject>} */
23-
states: Record<string, import("./state-object.js").StateObject>;
22+
/** @type {import("./interface.ts").StateStore} */
23+
states: import("./interface.ts").StateStore;
2424
urlService: import("../url/url-service.js").UrlService;
2525
urlServiceRules: import("../url/url-rules.js").UrlRules;
2626
$injector: any;
@@ -115,7 +115,16 @@ export class StateRegistryProvider {
115115
* @return {ng.BuiltStateDeclaration[]}
116116
*/
117117
getAll(): ng.BuiltStateDeclaration[];
118-
get(stateOrName: any, base: any, ...args: any[]): any;
118+
get(
119+
stateOrName: any,
120+
base: any,
121+
...args: any[]
122+
):
123+
| import("./interface.ts").StateDeclaration
124+
| (
125+
| import("./interface.ts").StateDeclaration
126+
| import("./interface.ts").BuiltStateDeclaration
127+
)[];
119128
/**
120129
* Registers a [[BuilderFunction]] for a specific [[StateObject]] property (e.g., `parent`, `url`, or `path`).
121130
* More than one BuilderFunction can be registered for a given property.

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,17 @@ export class UrlService {
2424
_urlRuleFactory: UrlRuleFactory;
2525
/**
2626
* The nested [[UrlRules]] API for managing URL rules and rewrites
27+
* @ignore
2728
* @type {UrlRules}
2829
*/
29-
rules: UrlRules;
30+
_rules: UrlRules;
3031
/**
3132
* The nested [[UrlConfig]] API to configure the URL and retrieve URL information
3233
* @type {import("./url-config.js").UrlConfigProvider}
3334
*/
34-
config: import("./url-config.js").UrlConfigProvider;
35-
/** Creates a new [[Param]] for a given location (DefType) */
36-
paramFactory: ParamFactory;
35+
_config: import("./url-config.js").UrlConfigProvider;
36+
/** @type {ParamFactory} Creates a new [[Param]] for a given location (DefType) */
37+
_paramFactory: ParamFactory;
3738
_urlListeners: any[];
3839
/**
3940
* Gets the path part of the current url

src/router/state/interface.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,12 @@ import {
1414
} from "../resolve/interface.ts";
1515
import { Resolvable } from "../resolve/resolvable.js";
1616
import { TargetState } from "./target-state.js";
17+
import { Glob } from "../glob/glob.js";
1718

1819
export type StateOrName = string | StateDeclaration | StateObject;
1920

21+
export type StateStore = Record<string, StateObject | BuiltStateDeclaration>;
22+
2023
export interface TransitionPromise extends Promise<StateObject> {
2124
transition: Transition;
2225
}
@@ -1001,6 +1004,8 @@ export type BuiltStateDeclaration = StateDeclaration & {
10011004

10021005
/** Optional inherited data */
10031006
data?: any;
1007+
1008+
_stateObjectCache?: { nameGlob: Glob } | null;
10041009
};
10051010

10061011
/**

src/router/state/state-builder.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ export function resolvablesBuilder(state) {
299299
export class StateBuilder {
300300
/**
301301
* @param {import('./state-matcher.js').StateMatcher} matcher
302-
* @param urlService
302+
* @param {ng.UrlService} urlService
303303
*/
304304
constructor(matcher, urlService) {
305305
this.matcher = matcher;
@@ -323,7 +323,7 @@ export class StateBuilder {
323323
// Keep track of the closest ancestor state that has a URL (i.e. is navigable)
324324
navigable: [getNavigableBuilder(isRoot)],
325325
// TODO
326-
params: [getParamsBuilder(urlService.paramFactory)],
326+
params: [getParamsBuilder(urlService._paramFactory)],
327327
// Each framework-specific ng-router implementation should define its own `views` builder
328328
// e.g., src/ng1/statebuilders/views.ts
329329
views: [],

src/router/state/state-matcher.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import { isString } from "../../shared/utils.js";
22
export class StateMatcher {
3-
constructor(_states) {
4-
this._states = _states;
3+
/** @param {import("./interface.ts").StateStore} states */
4+
constructor(states) {
5+
/** @type {import("./interface.ts").StateStore} */
6+
this._states = states;
57
}
68

79
isRelative(stateName) {
@@ -26,12 +28,12 @@ export class StateMatcher {
2628
) {
2729
return state;
2830
} else if (isStr && matchGlob) {
29-
const _states = Object.values(this._states);
31+
const states = Object.values(this._states);
3032

31-
const matches = _states.filter(
32-
(_state) =>
33-
_state.__stateObjectCache.nameGlob &&
34-
_state.__stateObjectCache.nameGlob.matches(name),
33+
const matches = states.filter(
34+
(stateObj) =>
35+
stateObj._stateObjectCache.nameGlob &&
36+
stateObj._stateObjectCache.nameGlob.matches(name),
3537
);
3638

3739
if (matches.length > 1) {

0 commit comments

Comments
 (0)