Skip to content

Commit f9ede9e

Browse files
crisbetoatscott
authored andcommitted
fix(core): ensure definitions compile
Includes the following changes to make sure the definitions for injectable compiler: 1. The types for the `factory` function now include the `parent` parameter. 2. `ɵɵFactoryDeclaration` is now defined as a function. We need this since the provider definition gets passed into the inejctable definition by reference. 3. `ɵɵdefineInjectable`, `ɵɵdefineNgModule` and `ɵɵdefinePipe` now return the typed definition, rather than `unknown`. This aligns with what we do for components and directives.
1 parent 2049698 commit f9ede9e

File tree

8 files changed

+23
-14
lines changed

8 files changed

+23
-14
lines changed

goldens/public-api/common/index.api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1042,7 +1042,7 @@ export abstract class ViewportScroller {
10421042
abstract setHistoryScrollRestoration(scrollRestoration: 'auto' | 'manual'): void;
10431043
abstract setOffset(offset: [number, number] | (() => [number, number])): void;
10441044
// (undocumented)
1045-
static ɵprov: unknown;
1045+
static ɵprov: i0.ɵɵInjectableDeclaration<NullViewportScroller | BrowserViewportScroller>;
10461046
}
10471047

10481048
// @public @deprecated

goldens/public-api/core/global_utils.api.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
55
```ts
66

7+
import { ɵɵInjectableDeclaration } from '@angular/core';
8+
79
// @public
810
export function applyChanges(component: {}): void;
911

goldens/public-api/core/index.api.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
55
```ts
66

7+
import * as _angular_core from '@angular/core';
78
import { Observable } from 'rxjs';
89
import { Subject } from 'rxjs';
910
import { Subscription } from 'rxjs';
@@ -989,7 +990,7 @@ export abstract class Injector {
989990
// (undocumented)
990991
static THROW_IF_NOT_FOUND: {};
991992
// (undocumented)
992-
static ɵprov: unknown;
993+
static ɵprov: _angular_core.ɵɵInjectableDeclaration<Injector>;
993994
}
994995

995996
// @public
@@ -1118,7 +1119,7 @@ export class IterableDiffers {
11181119
// (undocumented)
11191120
find(iterable: any): IterableDifferFactory;
11201121
// (undocumented)
1121-
static ɵprov: unknown;
1122+
static ɵprov: _angular_core.ɵɵInjectableDeclaration<IterableDiffers>;
11221123
}
11231124

11241125
// @public
@@ -1160,7 +1161,7 @@ export class KeyValueDiffers {
11601161
// (undocumented)
11611162
find(kv: any): KeyValueDifferFactory;
11621163
// (undocumented)
1163-
static ɵprov: unknown;
1164+
static ɵprov: _angular_core.ɵɵInjectableDeclaration<KeyValueDiffers>;
11641165
}
11651166

11661167
// @public
@@ -1417,7 +1418,7 @@ export class PendingTasks {
14171418
add(): () => void;
14181419
run(fn: () => Promise<unknown>): void;
14191420
// (undocumented)
1420-
static ɵprov: unknown;
1421+
static ɵprov: _angular_core.ɵɵInjectableDeclaration<PendingTasks>;
14211422
}
14221423

14231424
// @public
@@ -1757,7 +1758,7 @@ export abstract class Sanitizer {
17571758
// (undocumented)
17581759
abstract sanitize(context: SecurityContext, value: {} | string | null): string | null;
17591760
// (undocumented)
1760-
static ɵprov: unknown;
1761+
static ɵprov: _angular_core.ɵɵInjectableDeclaration<null>;
17611762
}
17621763

17631764
// @public
@@ -1918,7 +1919,7 @@ export class TransferState {
19181919
set<T>(key: StateKey<T>, value: T): void;
19191920
toJson(): string;
19201921
// (undocumented)
1921-
static ɵprov: unknown;
1922+
static ɵprov: _angular_core.ɵɵInjectableDeclaration<TransferState>;
19221923
}
19231924

19241925
// @public

goldens/public-api/core/rxjs-interop/index.api.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
55
```ts
66

7+
import * as _angular_core from '@angular/core';
78
import { MonoTypeOperatorFunction } from 'rxjs';
89
import { Observable } from 'rxjs';
910
import { Subscribable } from 'rxjs';

goldens/public-api/core/testing/index.api.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
55
```ts
66

7+
import * as _angular_core from '@angular/core';
78
import { Observable } from 'rxjs';
89
import { Subject } from 'rxjs';
910
import { Subscription } from 'rxjs';

packages/core/src/di/interface/defs.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,14 +167,14 @@ export interface InjectorTypeWithProviders<T> {
167167
export function ɵɵdefineInjectable<T>(opts: {
168168
token: unknown;
169169
providedIn?: Type<any> | 'root' | 'platform' | 'any' | 'environment' | null;
170-
factory: () => T;
171-
}): unknown {
170+
factory: (parent?: Type<any>) => T;
171+
}): ɵɵInjectableDeclaration<T> {
172172
return {
173173
token: opts.token,
174174
providedIn: (opts.providedIn as any) || null,
175175
factory: opts.factory,
176176
value: undefined,
177-
} as ɵɵInjectableDeclaration<T>;
177+
};
178178
}
179179

180180
/**

packages/core/src/render3/definition.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ export function ɵɵdefineNgModule<T>(def: {
419419

420420
/** Unique ID for the module that is used with `getModuleFactory`. */
421421
id?: string | null;
422-
}): unknown {
422+
}): NgModuleDef<T> {
423423
return noSideEffects(() => {
424424
const res: NgModuleDef<T> = {
425425
type: def.type,
@@ -608,8 +608,8 @@ export function ɵɵdefinePipe<T>(pipeDef: {
608608
* Whether the pipe is standalone.
609609
*/
610610
standalone?: boolean;
611-
}): unknown {
612-
return <PipeDef<T>>{
611+
}): PipeDef<T> {
612+
return {
613613
type: pipeDef.type,
614614
name: pipeDef.name,
615615
factory: null,

packages/core/src/render3/interfaces/public_definitions.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
* found in the LICENSE file at https://angular.dev/license
77
*/
88

9+
import {Type} from '../../interface/type';
10+
911
// This file contains types that will be published to npm in library typings files.
1012

1113
// Formatting does horrible things to these declarations.
@@ -78,7 +80,9 @@ export type ɵɵInjectorDeclaration<T> = unknown;
7880
/**
7981
* @publicApi
8082
*/
81-
export type ɵɵFactoryDeclaration<T, CtorDependencies extends CtorDependency[]> = unknown;
83+
export type ɵɵFactoryDeclaration<T, CtorDependencies extends CtorDependency[]> = (
84+
parent?: Type<any>,
85+
) => T;
8286

8387
/**
8488
* An object literal of this type is used to represent the metadata of a constructor dependency.

0 commit comments

Comments
 (0)