Skip to content

Commit 899cb4a

Browse files
devversionjosephperrott
authored andcommitted
refactor: add explicit types for exports relying on inferred call return type (#61316)
As part of the Bazel toolchain migration we noticed that implicit types generated by the TypeScript compiler sometimes end up referencing types from other packages (i.e. cross-package imports). These imports currently work just because the Bazel `ts_library` and `ng_module` rules automatically inserted a `<amd-module name="@angular/x" />` into `.d.ts` of packages. This helped TS figure out how to import a given file. Notably this is custom logic that is not occuring in vanilla TS or Angular compilations—so we will drop this magic as part of the toolchain cleanup! To improve code quality and keep the existing behavior working, we are doing the following: - adding a lint rule that reduces the risk of such imports breaking. The failure scenario without the rule is that API goldens show unexpected diffs, and types might be duplicated in a different package! - keeping the `<amd-module` headers, but we manually insert them into the package entry-points. This should ensure we don't regress anywhere; while we also improved general safety around this above. Long-term, isolated declarations or a lint rule from eslint-typescript can make this even more robust. PR Close #61316
1 parent 7be6e5d commit 899cb4a

File tree

42 files changed

+185
-97
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+185
-97
lines changed

adev/src/app/app.config.server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ const serverConfig: ApplicationConfig = {
1818
],
1919
};
2020

21-
export const config = mergeApplicationConfig(appConfig, serverConfig);
21+
export const config: ApplicationConfig = mergeApplicationConfig(appConfig, serverConfig);

adev/src/app/routes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import MainComponent from './main.component';
1616

1717
// Docs navigation data contains routes which navigates to /tutorials pages, in
1818
// that case we should load Tutorial component
19-
export const DOCS_ROUTES = mapNavigationItemsToRoutes(
19+
export const DOCS_ROUTES: Route[] = mapNavigationItemsToRoutes(
2020
flatNavigationData(SUB_NAVIGATION_DATA.docs).filter(
2121
(route) =>
2222
!route.path?.startsWith(PagePrefix.TUTORIALS) && route.path !== PagePrefix.PLAYGROUND,

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -874,16 +874,16 @@ export { PopStateEvent_2 as PopStateEvent }
874874
export const PRECONNECT_CHECK_BLOCKLIST: InjectionToken<(string | string[])[]>;
875875

876876
// @public
877-
export const provideCloudflareLoader: (path: string) => i0.Provider[];
877+
export const provideCloudflareLoader: (path: string) => Provider[];
878878

879879
// @public
880-
export const provideCloudinaryLoader: (path: string) => i0.Provider[];
880+
export const provideCloudinaryLoader: (path: string) => Provider[];
881881

882882
// @public
883-
export const provideImageKitLoader: (path: string) => i0.Provider[];
883+
export const provideImageKitLoader: (path: string) => Provider[];
884884

885885
// @public
886-
export const provideImgixLoader: (path: string) => i0.Provider[];
886+
export const provideImgixLoader: (path: string) => Provider[];
887887

888888
// @public
889889
export function provideNetlifyLoader(path?: string): Provider[];

goldens/public-api/platform-browser-dynamic/index.api.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import { Compiler } from '@angular/core';
88
import { CompilerFactory } from '@angular/core';
99
import { CompilerOptions } from '@angular/core';
10-
import * as i0 from '@angular/core';
10+
import { PlatformRef } from '@angular/core';
1111
import { StaticProvider } from '@angular/core';
1212
import { Version } from '@angular/core';
1313

@@ -18,7 +18,7 @@ export class JitCompilerFactory implements CompilerFactory {
1818
}
1919

2020
// @public (undocumented)
21-
export const platformBrowserDynamic: (extraProviders?: StaticProvider[]) => i0.PlatformRef;
21+
export const platformBrowserDynamic: (extraProviders?: StaticProvider[]) => PlatformRef;
2222

2323
// @public (undocumented)
2424
export const VERSION: Version;

goldens/public-api/platform-browser/testing/index.api.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import * as i0 from '@angular/core';
88
import * as i1 from '@angular/common';
9+
import { PlatformRef } from '@angular/core';
910
import { StaticProvider } from '@angular/core';
1011

1112
// @public
@@ -19,7 +20,7 @@ export class BrowserTestingModule {
1920
}
2021

2122
// @public
22-
export const platformBrowserTesting: (extraProviders?: StaticProvider[]) => i0.PlatformRef;
23+
export const platformBrowserTesting: (extraProviders?: StaticProvider[]) => PlatformRef;
2324

2425
// (No @packageDocumentation comment for this package)
2526

goldens/public-api/platform-server/testing/index.api.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66

77
import * as i0 from '@angular/core';
88
import * as i1 from '@angular/platform-browser-dynamic/testing';
9+
import { PlatformRef } from '@angular/core';
910
import { StaticProvider } from '@angular/core';
1011

1112
// @public
12-
export const platformServerTesting: (extraProviders?: StaticProvider[]) => i0.PlatformRef;
13+
export const platformServerTesting: (extraProviders?: StaticProvider[]) => PlatformRef;
1314

1415
// @public
1516
export class ServerTestingModule {

modules/benchmarks/src/change_detection/util.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import {getIntParameter} from '../util';
1010

11-
export const numViews = getIntParameter('viewCount');
11+
export const numViews: number = getIntParameter('viewCount');
1212

1313
export function newArray<T = any>(size: number): T[];
1414
export function newArray<T>(size: number, value: T): T[];

modules/ssr-benchmarks/src/app/app.config.server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ const serverConfig: ApplicationConfig = {
1414
providers: [provideServerRendering()],
1515
};
1616

17-
export const config = mergeApplicationConfig(appConfig, serverConfig);
17+
export const config: ApplicationConfig = mergeApplicationConfig(appConfig, serverConfig);

packages/common/src/directives/ng_optimized_image/image_loaders/cloudflare_loader.ts

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

9+
import {Provider} from '@angular/core';
910
import {PLACEHOLDER_QUALITY} from './constants';
1011
import {createImageLoader, ImageLoaderConfig} from './image_loader';
1112

@@ -20,7 +21,7 @@ import {createImageLoader, ImageLoaderConfig} from './image_loader';
2021
*
2122
* @publicApi
2223
*/
23-
export const provideCloudflareLoader = createImageLoader(
24+
export const provideCloudflareLoader: (path: string) => Provider[] = createImageLoader(
2425
createCloudflareUrl,
2526
ngDevMode ? ['https://<ZONE>/cdn-cgi/image/<OPTIONS>/<SOURCE-IMAGE>'] : undefined,
2627
);

packages/common/src/directives/ng_optimized_image/image_loaders/cloudinary_loader.ts

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

9+
import {Provider} from '@angular/core';
910
import {createImageLoader, ImageLoaderConfig, ImageLoaderInfo} from './image_loader';
1011

1112
/**
@@ -36,7 +37,7 @@ function isCloudinaryUrl(url: string): boolean {
3637
*
3738
* @publicApi
3839
*/
39-
export const provideCloudinaryLoader = createImageLoader(
40+
export const provideCloudinaryLoader: (path: string) => Provider[] = createImageLoader(
4041
createCloudinaryUrl,
4142
ngDevMode
4243
? [

0 commit comments

Comments
 (0)