Skip to content

Commit c874991

Browse files
committed
Improve angular type
1 parent 48fc7b5 commit c874991

File tree

28 files changed

+171
-52
lines changed

28 files changed

+171
-52
lines changed

@types/angular.d.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
export class Angular {
2-
_$cache: Map<number, import("./interface.ts").ExpandoStore>;
2+
/** @private @type {!Array<string|any>} */
3+
private _bootsrappedModules;
34
/** @public @type {ng.PubSubService} */
45
public $eventBus: ng.PubSubService;
56
/**
67
* @public
78
* @type {string} `version` from `package.json`
89
*/
910
public version: string;
10-
/** @type {!Array<string|any>} */
11-
_bootsrappedModules: Array<string | any>;
1211
/**
1312
* Gets the controller instance for a given element, if exists. Defaults to "ngControllerController"
1413
*
15-
* @type {(element: Element, name?: string) => ng.Scope|undefined}
14+
* @type {typeof getController}
1615
*/
17-
getController: (element: Element, name?: string) => ng.Scope | undefined;
16+
getController: typeof getController;
1817
/**
1918
* Return instance of InjectorService attached to element
2019
* @type {typeof getInjector}
@@ -25,8 +24,10 @@ export class Angular {
2524
* @type {typeof getScope}
2625
*/
2726
getScope: typeof getScope;
27+
/** @type {typeof errorHandlingConfig} */
2828
errorHandlingConfig: typeof errorHandlingConfig;
29-
$t: Readonly<Record<string, string>>;
29+
/** @type {ng.InjectionTokens} */
30+
$t: ng.InjectionTokens;
3031
/**
3132
*
3233
* The `angular.module` is a global place for creating, registering and retrieving AngularTS
@@ -158,6 +159,7 @@ export class Angular {
158159
export type ModuleRegistry = {
159160
[x: string]: NgModule;
160161
};
162+
import { getController } from "./shared/dom.js";
161163
import { getInjector } from "./shared/dom.js";
162164
import { getScope } from "./shared/dom.js";
163165
import { errorHandlingConfig } from "./shared/utils.js";

@types/core/scope/scope.d.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
export function nextId(): number;
21
/**
2+
* @private
33
* Creates a deep proxy for the target object, intercepting property changes
44
* and recursively applying proxies to nested objects.
55
*
@@ -16,8 +16,6 @@ export function createScope(target?: any, context?: Scope): Scope;
1616
* @returns {boolean}
1717
*/
1818
export function isNonScope(target: any): boolean;
19-
export const $postUpdateQueue: any[];
20-
export let rootScope: any;
2119
export class RootScopeProvider {
2220
rootScope: Scope;
2321
$get: (

@types/injection-tokens.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ export function provider(services: string[]): string[];
1111
* ```js
1212
*
1313
* myDirective.$inject = [
14-
* angular.$t._animate,
15-
* angular.$t._templateRequest,
14+
* angular.$t.$animate,
15+
* angular.$t.$templateRequest,
1616
* ];
1717
*
1818
* function myDirective($animate, $templateRequest) { ... }

@types/interface.d.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,52 @@
11
import { Attributes } from "./core/compile/attributes.js";
22
import { Scope } from "./core/scope/scope.js";
33
import { NgModelController } from "./directive/model/model.js";
4+
export declare const PublicInjectionTokens: {
5+
readonly $attrs: "$attrs";
6+
readonly $scope: "$scope";
7+
readonly $element: "$element";
8+
readonly $anchorScroll: "$anchorScroll";
9+
readonly $animate: "$animate";
10+
readonly $animateCss: "$animateCss";
11+
readonly $aria: "$aria";
12+
readonly $compile: "$compile";
13+
readonly $cookie: "$cookie";
14+
readonly $controller: "$controller";
15+
readonly $document: "$document";
16+
readonly $eventBus: "$eventBus";
17+
readonly $exceptionHandler: "$exceptionHandler";
18+
readonly $filter: "$filter";
19+
readonly $http: "$http";
20+
readonly $httpParamSerializer: "$httpParamSerializer";
21+
readonly $interpolate: "$interpolate";
22+
readonly $location: "$location";
23+
readonly $log: "$log";
24+
readonly $viewScroll: "$viewScroll";
25+
readonly $parse: "$parse";
26+
readonly $rest: "$rest";
27+
readonly $rootScope: "$rootScope";
28+
readonly $rootElement: "$rootElement";
29+
readonly $router: "$router";
30+
readonly $sce: "$sce";
31+
readonly $sceDelegate: "$sceDelegate";
32+
readonly $state: "$state";
33+
readonly $stateRegistry: "$stateRegistry";
34+
readonly $sse: "$sse";
35+
readonly $templateCache: "$templateCache";
36+
readonly $templateFactory: "$templateFactory";
37+
readonly $templateRequest: "$templateRequest";
38+
readonly $transitions: "$transitions";
39+
readonly $urlConfig: "$urlConfig";
40+
readonly $url: "$url";
41+
readonly $view: "$view";
42+
readonly $window: "$window";
43+
readonly $provide: "$provide";
44+
readonly $injector: "$injector";
45+
readonly $compileProvider: "$compileProvider";
46+
readonly $animateProvider: "$animateProvider";
47+
readonly $filterProvider: "$filterProvider";
48+
readonly $controllerProvider: "$controllerProvider";
49+
};
450
/**
551
* Configuration options for the AngularTS bootstrap process.
652
*

@types/namespace.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import {
4848
ControllerConstructor as TControllerConstructor,
4949
Injectable as TInjectable,
5050
Expression as TExpression,
51+
PublicInjectionTokens,
5152
} from "./interface.ts";
5253
import {
5354
SseService as TSseService,
@@ -200,5 +201,6 @@ declare global {
200201
type StateObject = TStateObject;
201202
type AnchorScrollFunction = TAnchorScrollFunction;
202203
type AnchorScrollObject = TAnchorScrollObject;
204+
type InjectionTokens = typeof PublicInjectionTokens;
203205
}
204206
}

@types/services/cookie/cookie.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export class CookieService {
2828
);
2929
/** @private @type {ng.CookieOptions} */
3030
private _defaults;
31-
/** @private */
31+
/** @private @type {ng.ExceptionHandlerService} */
3232
private _$exceptionHandler;
3333
/**
3434
* Retrieves a raw cookie value.

@types/services/pubsub/pubsub.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ export class PubSub {
7272
*/
7373
publish(topic: string, ...args: any[]): boolean;
7474
}
75+
/** @private */
7576
export const EventBus: PubSub;
7677
/**
7778
* /**

@types/shared/validate.d.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,19 @@ export function validateArray(arg: any, name: string): any;
3131
* @throws {TypeError} If the value does not satisfy the validator.
3232
*/
3333
export function validateIsString(arg: any, name: string): any;
34+
/**
35+
* @template T
36+
* @param {unknown} arg - The value to validate.
37+
* @param {new (...args: any[]) => T} type - The constructor to check against.
38+
* @param {string} name - Parameter name (included in error message).
39+
* @returns {T} The validated instance.
40+
* @throws {TypeError} If the value is not an instance of the specified type.
41+
*/
42+
export function validateInstanceOf<T>(
43+
arg: unknown,
44+
type: new (...args: any[]) => T,
45+
name: string,
46+
): T;
3447
export const BADARG: "badarg";
3548
export const BADARGKEY: "badarg: key";
3649
export const BADARGVALUE: "badarg: value";

docs/static/typedoc/assets/navigation.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)