Skip to content

Commit 5275892

Browse files
committed
refactor(@angular/cli): remove any type usage
1 parent 8336898 commit 5275892

File tree

9 files changed

+25
-34
lines changed

9 files changed

+25
-34
lines changed

packages/angular/cli/commands/add-impl.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,7 @@ export class AddCommand extends SchematicCommand<AddCommandSchema> {
102102
if (latestManifest && Object.keys(latestManifest.peerDependencies).length === 0) {
103103
if (latestManifest.name === '@angular/pwa') {
104104
const version = await this.findProjectVersion('@angular/cli');
105-
// tslint:disable-next-line:no-any
106-
const semverOptions = { includePrerelease: true } as any;
105+
const semverOptions = { includePrerelease: true };
107106

108107
if (
109108
version &&
@@ -299,8 +298,7 @@ export class AddCommand extends SchematicCommand<AddCommandSchema> {
299298
continue;
300299
}
301300

302-
// tslint:disable-next-line:no-any
303-
const options = { includePrerelease: true } as any;
301+
const options = { includePrerelease: true };
304302

305303
if (
306304
!intersects(version, peerIdentifier.rawSpec, options) &&

packages/angular/cli/commands/new-impl.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.io/license
77
*/
8-
9-
// tslint:disable:no-global-tslint-disable no-any
108
import { Arguments } from '../models/interface';
119
import { SchematicCommand } from '../models/schematic-command';
1210
import { Schema as NewCommandSchema } from './new';

packages/angular/cli/commands/update-impl.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,11 @@ export class UpdateCommand extends Command<UpdateCommandSchema> {
220220
return this.executePackageMigrations(migrations, packageName, commit);
221221
}
222222

223-
// tslint:disable-next-line: no-any
224-
private async executePackageMigrations(migrations: any[], packageName: string, commit = false): Promise<boolean> {
223+
private async executePackageMigrations(
224+
migrations: Iterable<{ name: string; description: string; collection: { name: string }}>,
225+
packageName: string,
226+
commit = false,
227+
): Promise<boolean> {
225228
for (const migration of migrations) {
226229
this.logger.info(`${colors.symbols.pointer} ${migration.description.replace(/\. /g, '.\n ')}`);
227230

packages/angular/cli/lib/init.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ function _fromPackageJson(cwd = process.cwd()): SemVer | null {
4242
if (process.env['NG_CLI_PROFILING']) {
4343
let profiler: {
4444
startProfiling: (name?: string, recsamples?: boolean) => void;
45-
stopProfiling: (name?: string) => any; // tslint:disable-line:no-any
45+
stopProfiling: (name?: string) => unknown;
4646
};
4747
try {
4848
profiler = require('v8-profiler-node8'); // tslint:disable-line:no-implicit-dependencies

packages/angular/cli/models/command.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.io/license
77
*/
8-
9-
// tslint:disable:no-global-tslint-disable no-any
108
import { analytics, logging, strings, tags } from '@angular-devkit/core';
119
import * as path from 'path';
1210
import { colors } from '../utilities/color';

packages/angular/cli/utilities/color.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ export function removeColor(text: string): string {
1717
return text.replace(new RegExp(ansiColors.ansiRegex), '');
1818
}
1919

20-
// tslint:disable-next-line: no-any
21-
const colors = (ansiColors as any).create() as typeof ansiColors;
20+
// create a separate instance to prevent unintended global changes to the color configuration
21+
// create function is not defined in the typings
22+
const colors = (ansiColors as typeof ansiColors & { create: () => typeof ansiColors }).create();
2223
colors.enabled = supportsColor;
2324

2425
export { colors };

packages/angular/cli/utilities/config.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,16 +93,14 @@ export class AngularWorkspace {
9393

9494
// tslint:disable-next-line: no-any
9595
getCli(): Record<string, any> {
96-
// tslint:disable-next-line: no-any
97-
return (this.workspace.extensions['cli'] as Record<string, any>) || {};
96+
return (this.workspace.extensions['cli'] as Record<string, unknown>) || {};
9897
}
9998

10099
// tslint:disable-next-line: no-any
101100
getProjectCli(projectName: string): Record<string, any> {
102101
const project = this.workspace.projects.get(projectName);
103102

104-
// tslint:disable-next-line: no-any
105-
return (project?.extensions['cli'] as Record<string, any>) || {};
103+
return (project?.extensions['cli'] as Record<string, unknown>) || {};
106104
}
107105
}
108106

packages/angular/cli/utilities/package-metadata.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export interface PackageMetadata {
5454
name: string;
5555
tags: { [tag: string]: PackageManifest | undefined };
5656
versions: Record<string, PackageManifest>;
57+
'dist-tags'?: unknown;
5758
}
5859

5960
let npmrc: { [key: string]: string };
@@ -141,16 +142,15 @@ function readOptions(
141142
return options;
142143
}
143144

144-
function normalizeManifest(rawManifest: {}): PackageManifest {
145+
function normalizeManifest(rawManifest: { name: string; version: string }): PackageManifest {
145146
// TODO: Fully normalize and sanitize
146147

147148
return {
148149
dependencies: {},
149150
devDependencies: {},
150151
peerDependencies: {},
151152
optionalDependencies: {},
152-
// tslint:disable-next-line:no-any
153-
...(rawManifest as any),
153+
...rawManifest,
154154
};
155155
}
156156

@@ -187,14 +187,13 @@ export async function fetchPackageMetadata(
187187

188188
if (response.versions) {
189189
for (const [version, manifest] of Object.entries(response.versions)) {
190-
metadata.versions[version] = normalizeManifest(manifest as {});
190+
metadata.versions[version] = normalizeManifest(manifest as { name: string; version: string });
191191
}
192192
}
193193

194194
if (response['dist-tags']) {
195195
// Store this for use with other npm utility packages
196-
// tslint:disable-next-line: no-any
197-
(metadata as any)['dist-tags'] = response['dist-tags'];
196+
metadata['dist-tags'] = response['dist-tags'];
198197

199198
for (const [tag, version] of Object.entries(response['dist-tags'])) {
200199
const manifest = metadata.versions[version as string];

packages/angular/cli/utilities/project.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.io/license
77
*/
8-
9-
// tslint:disable:no-global-tslint-disable no-any
108
import { normalize } from '@angular-devkit/core';
119
import * as fs from 'fs';
1210
import * as os from 'os';
@@ -56,16 +54,14 @@ export function getWorkspaceDetails(): CommandWorkspace | null {
5654
};
5755
}
5856

59-
function containsCliDep(obj: any): boolean {
57+
function containsCliDep(obj?: {
58+
dependencies?: Record<string, string>;
59+
devDependencies?: Record<string, string>;
60+
}): boolean {
6061
const pkgName = '@angular/cli';
61-
if (obj) {
62-
if (obj.dependencies && obj.dependencies[pkgName]) {
63-
return true;
64-
}
65-
if (obj.devDependencies && obj.devDependencies[pkgName]) {
66-
return true;
67-
}
62+
if (!obj) {
63+
return false;
6864
}
6965

70-
return false;
66+
return !!(obj.dependencies?.[pkgName] || obj.devDependencies?.[pkgName]);
7167
}

0 commit comments

Comments
 (0)