Skip to content

Commit 8afd4b1

Browse files
committed
Type improvements
1 parent 2f8b881 commit 8afd4b1

File tree

18 files changed

+175
-822
lines changed

18 files changed

+175
-822
lines changed

@types/core/parse/parse.d.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,8 @@ export class ParseProvider {
2929
identifierStart?: (arg0: any) => boolean,
3030
identifierContinue?: (arg0: any) => boolean,
3131
) => ParseProvider;
32-
$get: (string | (($filter: (any: any) => any) => any))[];
32+
$get: (
33+
| string
34+
| (($filter: (any: any) => any) => import("./interface.ts").ParseService)
35+
)[];
3336
}

@types/directive/form/form.d.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ export class FormController {
108108
$$success: {};
109109
$pending: any;
110110
$$classCache: {};
111+
$target: {};
111112
/**
112113
* Rollback all form controls pending updates to the `$modelValue`.
113114
*
@@ -154,8 +155,9 @@ export class FormController {
154155
* Likewise, adding a control to, or removing a control from the form is not reflected
155156
* in the shallow copy. That means you should get a fresh copy from `$getControls()` every time
156157
* you need access to the controls.
158+
* @returns {ReadonlyArray<FormController>}
157159
*/
158-
$getControls(): any[];
160+
$getControls(): ReadonlyArray<FormController>;
159161
$$renameControl(control: any, newName: any): void;
160162
/**
161163
* Deregister a control from the form.
@@ -166,8 +168,9 @@ export class FormController {
166168
* form. `$dirty`, `$submitted` states will not be changed, because the expected behavior can be
167169
* different from case to case. For example, removing the only `$dirty` control from a form may or
168170
* may not mean that the form is still `$dirty`.
171+
* @param {FormController } control
169172
*/
170-
$removeControl(control: any): void;
173+
$removeControl(control: FormController): void;
171174
/**
172175
* Sets the form to a dirty state.
173176
*
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
export interface ModelValidators {
2+
/**
3+
* viewValue is any because it can be an object that is called in the view like $viewValue.name:$viewValue.subName
4+
*/
5+
[index: string]: (modelValue: any, viewValue: any) => boolean;
6+
}
7+
export interface AsyncModelValidators {
8+
[index: string]: (modelValue: any, viewValue: any) => Promise<any>;
9+
}
10+
export interface ModelParser {
11+
(value: any): any;
12+
}
13+
export interface ModelFormatter {
14+
(value: any): any;
15+
}
16+
export interface ModelViewChangeListener {
17+
(): void;
18+
}

@types/directive/model/model.d.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,16 @@ export class NgModelController {
7272
$modelValue: any;
7373
/** @type {any} */
7474
$$rawModelValue: any;
75-
/** @type {any} */
76-
$validators: any;
77-
/** @type {any} */
78-
$asyncValidators: any;
79-
/** @type {Array<any>} */
80-
$parsers: Array<any>;
81-
/** @type {Array<any>} */
82-
$formatters: Array<any>;
83-
/** @type {Array<any>} */
84-
$viewChangeListeners: Array<any>;
75+
/** @type {import("./interface.ts").ModelValidators} */
76+
$validators: import("./interface.ts").ModelValidators;
77+
/** @type {import("./interface.ts").AsyncModelValidators} */
78+
$asyncValidators: import("./interface.ts").AsyncModelValidators;
79+
/** @type {Array<import("./interface.ts").ModelParser>} */
80+
$parsers: Array<import("./interface.ts").ModelParser>;
81+
/** @type {Array<import("./interface.ts").ModelFormatter>} */
82+
$formatters: Array<import("./interface.ts").ModelFormatter>;
83+
/** @type {Array<import("./interface.ts").ModelViewChangeListener>} */
84+
$viewChangeListeners: Array<import("./interface.ts").ModelViewChangeListener>;
8585
/** @type {boolean} */
8686
$untouched: boolean;
8787
/** @type {boolean} */
@@ -398,10 +398,12 @@ export class NgModelController {
398398
* **Note:** it is not possible to override the `getterSetter` option.
399399
* </div>
400400
*
401-
* @param {Object} options a hash of settings to override the previous options
401+
* @param {import("../../interface.ts").NgModelOptions} options a hash of settings to override the previous options
402402
*
403403
*/
404-
$overrideModelOptions(options: any): void;
404+
$overrideModelOptions(
405+
options: import("../../interface.ts").NgModelOptions,
406+
): void;
405407
/**
406408
* Runs the model -> view pipeline on the current
407409
* {@link ngModel.NgModelController#$modelValue $modelValue}.

@types/interface.d.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,24 @@ export type CloneAttachFunction = (
465465
clonedElement?: Element,
466466
scope?: Scope,
467467
) => any;
468+
export interface TemplateLinkingFunction {
469+
(
470+
scope: ng.Scope,
471+
cloneAttachFn?: CloneAttachFunction,
472+
options?: TemplateLinkingFunctionOptions,
473+
): Element;
474+
}
475+
export interface TemplateLinkingFunctionOptions {
476+
parentBoundTranscludeFn?: TranscludeFunctionObject | undefined;
477+
transcludeControllers?:
478+
| {
479+
[controller: string]: {
480+
instance: Controller;
481+
};
482+
}
483+
| undefined;
484+
futureParentElement?: Element | undefined;
485+
}
468486
/**
469487
* Configuration for ngModel behavior.
470488
*/

@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 {import("./interface.js").StateStore} states
5+
* @param {import("./interface.ts").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: import("./interface.js").StateStore,
12+
states: import("./interface.ts").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: import("./interface.js").StateStore;
19+
states: import("./interface.ts").StateStore;
2020
builder: any;
2121
listeners: any;
2222
/**
2323
* @type {Array<StateObject>}
2424
*/
2525
queue: Array<StateObject>;
2626
register(stateDecl: any): StateObject;
27-
flush(): import("./interface.js").StateStore;
27+
flush(): import("./interface.ts").StateStore;
2828
/**
2929
*
3030
* @param {ng.StateDeclaration} state

@types/services/http/http.d.ts

Lines changed: 6 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,7 @@ export function defaultHttpResponseTransform(data: any, headers: any): any;
2323
*/
2424
export function HttpProvider(): void;
2525
export class HttpProvider {
26-
defaults: {
27-
transformResponse: (typeof defaultHttpResponseTransform)[];
28-
transformRequest: ((data: any) => any)[];
29-
headers: {
30-
common: {
31-
Accept: string;
32-
};
33-
post: {
34-
"Content-Type": string;
35-
};
36-
put: {
37-
"Content-Type": string;
38-
};
39-
patch: {
40-
"Content-Type": string;
41-
};
42-
};
43-
xsrfCookieName: string;
44-
xsrfHeaderName: string;
45-
paramSerializer: string;
46-
};
26+
defaults: import("./interface.ts").HttpProviderDefaults;
4727
/**
4828
* Configure $http service to combine processing of multiple http responses received at around
4929
* the same time via {@link ng.$rootScope.Scope#$applyAsync $rootScope.$applyAsync}. This can result in
@@ -68,8 +48,11 @@ export class HttpProvider {
6848
* array, on request, but reverse order, on response.
6949
*
7050
* {@link ng.$http#interceptors Interceptors detailed info}
51+
* @type {Array<string | ng.Injectable<import("./interface.ts").HttpInterceptorFactory>>}
7152
*/
72-
interceptors: any[];
53+
interceptors: Array<
54+
string | ng.Injectable<import("./interface.ts").HttpInterceptorFactory>
55+
>;
7356
/**
7457
* Array containing URLs whose origins are trusted to receive the XSRF token. See the
7558
* {@link ng.$http#security-considerations Security Considerations} sections for more details on
@@ -124,27 +107,7 @@ export class HttpProvider {
124107
*
125108
* See "Setting HTTP Headers" and "Transforming Requests and Responses" sections above.
126109
*/
127-
defaults: {
128-
transformResponse: (typeof defaultHttpResponseTransform)[];
129-
transformRequest: ((data: any) => any)[];
130-
headers: {
131-
common: {
132-
Accept: string;
133-
};
134-
post: {
135-
"Content-Type": string;
136-
};
137-
put: {
138-
"Content-Type": string;
139-
};
140-
patch: {
141-
"Content-Type": string;
142-
};
143-
};
144-
xsrfCookieName: string;
145-
xsrfHeaderName: string;
146-
paramSerializer: string;
147-
};
110+
defaults: import("./interface.ts").HttpProviderDefaults;
148111
})
149112
)[];
150113
}

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ export interface HttpHeadersGetter {
44
};
55
(headerName: string): string;
66
}
7+
export interface HttpPromiseCallback<T> {
8+
(
9+
data: T,
10+
status: number,
11+
headers: HttpHeadersGetter,
12+
config: RequestConfig,
13+
): void;
14+
}
715
export interface HttpRequestConfigHeaders {
816
[requestType: string]: any;
917
common?: any;
@@ -18,6 +26,9 @@ export interface HttpRequestTransformer {
1826
export interface HttpResponseTransformer {
1927
(data: any, headersGetter: HttpHeadersGetter, status: number): any;
2028
}
29+
export interface HttpHeaderType {
30+
[requestType: string]: string | ((config: RequestConfig) => string);
31+
}
2132
/**
2233
* Object that controls the defaults for $http provider. Not all fields of RequestShortcutConfig can be configured
2334
* via defaults and the docs do not say which. The following is based on the inspection of the source code.
@@ -228,3 +239,14 @@ export type HttpParams = Record<
228239
* A function that serializes an object into a URL-encoded query string.
229240
*/
230241
export type HttpParamSerializer = (params?: HttpParams) => string;
242+
export interface HttpInterceptor {
243+
request?(config: RequestConfig): RequestConfig | Promise<RequestConfig>;
244+
requestError?(rejection: any): RequestConfig | Promise<RequestConfig>;
245+
response?<T>(
246+
response: HttpResponse<T>,
247+
): Promise<HttpResponse<T>> | HttpResponse<T>;
248+
responseError?<T>(rejection: any): Promise<HttpResponse<T>> | HttpResponse<T>;
249+
}
250+
export interface HttpInterceptorFactory {
251+
(...args: any[]): HttpInterceptor;
252+
}

0 commit comments

Comments
 (0)