Skip to content

Commit fcbf6f9

Browse files
committed
build: fix typescript compilation errors
1 parent 45b6954 commit fcbf6f9

22 files changed

+57
-55
lines changed

tests/legacy-cli/e2e/setup/010-local-publish.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { execWithEnv, extractNpmEnv } from '../utils/process';
33
import { isPrereleaseCli } from '../utils/project';
44

55
export default async function () {
6-
const testRegistry = getGlobalVariable('package-registry');
6+
const testRegistry: string = getGlobalVariable('package-registry');
77
await execWithEnv(
88
'npm',
99
[

tests/legacy-cli/e2e/setup/100-global-cli.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export default async function () {
77
return;
88
}
99

10-
const testRegistry = getGlobalVariable('package-registry');
10+
const testRegistry: string = getGlobalVariable('package-registry');
1111

1212
// Install global Angular CLI.
1313
await silentNpm('install', '--global', '@angular/cli', `--registry=${testRegistry}`);

tests/legacy-cli/e2e/setup/300-log-environment.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export default async function () {
1010
return;
1111
}
1212

13-
console.log(` ${envName}: ${process.env[envName].replace(/[\n\r]+/g, '\n ')}`);
13+
console.log(` ${envName}: ${process.env[envName]!.replace(/[\n\r]+/g, '\n ')}`);
1414
});
1515

1616
await node('--version');

tests/legacy-cli/e2e/setup/500-create-project.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,10 @@ export default async function () {
1717
process.chdir(argv.reuse);
1818
await gitClean();
1919
} else {
20-
const extraArgs = [];
21-
2220
// Ensure local test registry is used when outside a project
2321
await setNPMConfigRegistry(true);
2422

25-
await ng('new', 'test-project', '--skip-install', ...extraArgs);
23+
await ng('new', 'test-project', '--skip-install');
2624
await expectFileToExist(join(process.cwd(), 'test-project'));
2725
process.chdir('./test-project');
2826

tests/legacy-cli/e2e/tests/build/build-app-shell-with-schematic.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@ export default async function () {
1212

1313
const isSnapshotBuild = getGlobalVariable('argv')['ng-snapshots'];
1414
if (isSnapshotBuild) {
15-
const packagesToInstall = [];
15+
const packagesToInstall: string[] = [];
1616
await updateJsonFile('package.json', (packageJson) => {
1717
const dependencies = packageJson['dependencies'];
1818
// Iterate over all of the packages to update them to the snapshot version.
19-
for (const [name, version] of Object.entries(snapshots.dependencies)) {
19+
for (const [name, version] of Object.entries(
20+
snapshots.dependencies as { [p: string]: string },
21+
)) {
2022
if (name in dependencies && dependencies[name] !== version) {
2123
packagesToInstall.push(version);
2224
}

tests/legacy-cli/e2e/tests/build/platform-server.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ export default async function () {
1212

1313
const isSnapshotBuild = getGlobalVariable('argv')['ng-snapshots'];
1414
if (isSnapshotBuild) {
15-
const packagesToInstall = [];
15+
const packagesToInstall: string[] = [];
1616
await updateJsonFile('package.json', (packageJson) => {
1717
const dependencies = packageJson['dependencies'];
1818
// Iterate over all of the packages to update them to the snapshot version.
19-
for (const [name, version] of Object.entries(snapshots.dependencies)) {
19+
for (const [name, version] of Object.entries<string>(snapshots.dependencies)) {
2020
if (name in dependencies && dependencies[name] !== version) {
2121
packagesToInstall.push(version);
2222
}

tests/legacy-cli/e2e/tests/build/prod-build.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export default async function () {
3939
}
4040

4141
const indexContent = await readFile('dist/test-project/index.html');
42-
const mainPath = indexContent.match(/src="(main\.[0-9a-zA-Z]{0,32}\.js)"/)[1];
42+
const mainPath = indexContent.match(/src="(main\.[0-9a-zA-Z]{0,32}\.js)"/)![1];
4343

4444
// Content checks
4545
await expectFileToMatch(`dist/test-project/${mainPath}`, bootstrapRegExp);

tests/legacy-cli/e2e/tests/commands/add/add-pwa.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ export default async function () {
5353

5454
// It should correctly generate assetGroups and include at least one URL in each group.
5555
const ngswJson = JSON.parse(await readFile(ngswPath));
56-
const assetGroups = ngswJson.assetGroups.map(({ name, urls }) => ({
56+
// @ts-ignore
57+
const assetGroups: any[] = ngswJson.assetGroups.map(({ name, urls }) => ({
5758
name,
5859
urlCount: urls.length,
5960
}));

tests/legacy-cli/e2e/tests/i18n/ivy-localize-basehref.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { ng } from '../../utils/process';
1111
import { updateJsonFile } from '../../utils/project';
1212
import { externalServer, langTranslations, setupI18nConfig } from './setup';
1313

14-
const baseHrefs = {
14+
const baseHrefs: { [l: string]: string } = {
1515
'en-US': '/en/',
1616
fr: '/fr-FR/',
1717
de: '',
@@ -59,7 +59,7 @@ export default async function () {
5959
await ng('e2e', `--configuration=${lang}`, '--port=0');
6060

6161
// Execute Application E2E tests for a production build without dev server
62-
const server = externalServer(outputPath, baseHrefs[lang] || '/');
62+
const server = externalServer(outputPath, (baseHrefs[lang] as string) || '/');
6363
try {
6464
await ng(
6565
'e2e',

tests/legacy-cli/e2e/tests/i18n/ivy-localize-hashes.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export default async function () {
2727
continue;
2828
}
2929

30-
hashes.set(`${lang}/${match.groups.name}`, match.groups.hash);
30+
hashes.set(`${lang}/${match!.groups!.name}`, match!.groups!.hash);
3131
}
3232
}
3333

@@ -48,12 +48,12 @@ export default async function () {
4848
continue;
4949
}
5050

51-
const id = `${lang}/${match.groups.name}`;
51+
const id = `${lang}/${match!.groups!.name}`;
5252
const hash = hashes.get(id);
5353
if (!hash) {
5454
throw new Error('Unexpected output entry: ' + id);
5555
}
56-
if (hash === match.groups.hash) {
56+
if (hash === match!.groups!.hash) {
5757
throw new Error('Hash value did not change for entry: ' + id);
5858
}
5959

tests/legacy-cli/e2e/tests/i18n/setup.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,12 @@ export const formats = {
9898
'json': {
9999
ext: 'json',
100100
sourceCheck: '"locale": "en-US"',
101-
replacements: [],
101+
replacements: [] as RegExp[][],
102102
},
103103
'arb': {
104104
ext: 'arb',
105105
sourceCheck: '"@@locale": "en-US"',
106-
replacements: [],
106+
replacements: [] as RegExp[][],
107107
},
108108
};
109109

@@ -248,7 +248,7 @@ export async function setupI18nConfig(format: keyof typeof formats = 'xlf') {
248248
for (const { lang, translationReplacements } of langTranslations) {
249249
if (lang != sourceLocale) {
250250
await copyFile(translationFile, `src/locale/messages.${lang}.${formats[format].ext}`);
251-
for (const replacements of translationReplacements) {
251+
for (const replacements of translationReplacements!) {
252252
await replaceInFile(
253253
`src/locale/messages.${lang}.${formats[format].ext}`,
254254
new RegExp(replacements[0], 'g'),

tests/legacy-cli/e2e/tests/misc/completion-prompt.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ source <(ng completion script)
408408

409409
const localCliDir = path.join(projectDir, 'node_modules', '.bin');
410410
const localCliBinary = path.join(localCliDir, 'ng');
411-
const pathDirs = process.env['PATH'].split(':');
411+
const pathDirs = process.env['PATH']!.split(':');
412412
const pathEnvVar = [...pathDirs, localCliDir].join(':');
413413
const { stdout } = await execWithEnv(localCliBinary, ['version'], {
414414
...DEFAULT_ENV,

tests/legacy-cli/e2e/tests/misc/e2e-host.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { killAllProcesses, ng } from '../../utils/process';
33
import { updateJsonFile } from '../../utils/project';
44

55
export default async function () {
6-
const interfaces = [].concat.apply([], Object.values(os.networkInterfaces()));
6+
const interfaces = Object.values(os.networkInterfaces()).flat() as os.NetworkInterfaceInfo[];
77
let host = '';
88
for (const { family, address, internal } of interfaces) {
99
if (family === 'IPv4' && !internal) {

tests/legacy-cli/e2e/tests/misc/http-headers.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export default async function () {
2424
};
2525
});
2626

27-
let errorMessage = null;
27+
let errorMessage: string | null = null;
2828
try {
2929
await ng('e2e');
3030
} catch (error) {

tests/legacy-cli/e2e/tests/misc/npm-7.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export default async function () {
3939

4040
const currentDirectory = process.cwd();
4141

42-
const extraArgs = [];
42+
const extraArgs: string[] = [];
4343
if (isPrereleaseCli()) {
4444
extraArgs.push('--next');
4545
}

tests/legacy-cli/e2e/tests/misc/public-host.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ export default function () {
88

99
const firstLocalIp = Object.values(os.networkInterfaces())
1010
.flat()
11-
.filter((ni) => ni.family === 'IPv4' && !ni.internal)
12-
.map((ni) => ni.address)
11+
.filter((ni) => ni?.family === 'IPv4' && !ni?.internal)
12+
.map((ni) => ni!.address)
1313
.shift();
1414
const publicHost = `${firstLocalIp}:4200`;
1515
const localAddress = `http://${publicHost}`;

tests/legacy-cli/e2e/tests/update/update-secure-registry.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export default async function () {
88
delete process.env['NPM_CONFIG_REGISTRY'];
99
const worksMessage = 'We analyzed your package.json';
1010

11-
const extraArgs = [];
11+
const extraArgs: string[] = [];
1212
if (isPrereleaseCli()) {
1313
extraArgs.push('--next');
1414
}

tests/legacy-cli/e2e/utils/env.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ export function setGlobalVariable(name: string, value: any) {
44
global[name] = value;
55
}
66

7-
export function getGlobalVariable(name: string): any {
7+
export function getGlobalVariable<T = any>(name: string): T {
88
if (!(name in global)) {
99
throw new Error(`Trying to access variable "${name}" but it's not defined.`);
1010
}
11-
return global[name];
11+
return global[name] as T;
1212
}

tests/legacy-cli/e2e/utils/fs.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export function symlinkFile(from: string, to: string, type?: string): Promise<vo
2929
return fs.symlink(from, to, type);
3030
}
3131

32-
export function createDir(path: string): Promise<string> {
32+
export function createDir(path: string): Promise<string | undefined> {
3333
return fs.mkdir(path, { recursive: true });
3434
}
3535

tests/legacy-cli/e2e/utils/process.ts

+19-18
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import treeKill from 'tree-kill';
1010
interface ExecOptions {
1111
silent?: boolean;
1212
waitForMatch?: RegExp;
13-
env?: { [varname: string]: string };
13+
env?: NodeJS.ProcessEnv;
1414
stdin?: string;
1515
cwd?: string;
1616
}
@@ -61,7 +61,8 @@ function _exec(options: ExecOptions, cmd: string, args: string[]): Promise<Proce
6161
}
6262

6363
const childProcess = child_process.spawn(cmd, args, spawnOptions);
64-
childProcess.stdout.on('data', (data: Buffer) => {
64+
// @ts-ignore
65+
childProcess.stdout!.on('data', (data: Buffer) => {
6566
stdout += data.toString('utf-8');
6667
if (options.silent) {
6768
return;
@@ -72,7 +73,8 @@ function _exec(options: ExecOptions, cmd: string, args: string[]): Promise<Proce
7273
.filter((line) => line !== '')
7374
.forEach((line) => console.log(' ' + line));
7475
});
75-
childProcess.stderr.on('data', (data: Buffer) => {
76+
// @ts-ignore
77+
childProcess.stderr!.on('data', (data: Buffer) => {
7678
stderr += data.toString('utf-8');
7779
if (options.silent) {
7880
return;
@@ -118,13 +120,15 @@ function _exec(options: ExecOptions, cmd: string, args: string[]): Promise<Proce
118120

119121
if (options.waitForMatch) {
120122
const match = options.waitForMatch;
121-
childProcess.stdout.on('data', (data: Buffer) => {
123+
// @ts-ignore
124+
childProcess.stdout!.on('data', (data: Buffer) => {
122125
if (data.toString().match(match)) {
123126
resolve({ stdout, stderr });
124127
matched = true;
125128
}
126129
});
127-
childProcess.stderr.on('data', (data: Buffer) => {
130+
// @ts-ignore
131+
childProcess.stderr!.on('data', (data: Buffer) => {
128132
if (data.toString().match(match)) {
129133
resolve({ stdout, stderr });
130134
matched = true;
@@ -134,16 +138,16 @@ function _exec(options: ExecOptions, cmd: string, args: string[]): Promise<Proce
134138

135139
// Provide input to stdin if given.
136140
if (options.stdin) {
137-
childProcess.stdin.write(options.stdin);
138-
childProcess.stdin.end();
141+
childProcess.stdin!.write(options.stdin);
142+
childProcess.stdin!.end();
139143
}
140144
});
141145
}
142146

143147
export function extractNpmEnv() {
144148
return Object.keys(process.env)
145149
.filter((v) => NPM_CONFIG_RE.test(v))
146-
.reduce(
150+
.reduce<NodeJS.ProcessEnv>(
147151
(vars, n) => {
148152
vars[n] = process.env[n];
149153
return vars;
@@ -171,13 +175,15 @@ export function waitForAnyProcessOutputToMatch(
171175
new Promise((resolve) => {
172176
let stdout = '';
173177
let stderr = '';
174-
childProcess.stdout.on('data', (data: Buffer) => {
178+
// @ts-ignore
179+
childProcess.stdout!.on('data', (data: Buffer) => {
175180
stdout += data.toString();
176181
if (data.toString().match(match)) {
177182
resolve({ stdout, stderr });
178183
}
179184
});
180-
childProcess.stderr.on('data', (data: Buffer) => {
185+
// @ts-ignore
186+
childProcess.stderr!.on('data', (data: Buffer) => {
181187
stderr += data.toString();
182188
if (data.toString().match(match)) {
183189
resolve({ stdout, stderr });
@@ -216,19 +222,14 @@ export function silentExec(cmd: string, ...args: string[]) {
216222
return _exec({ silent: true }, cmd, args);
217223
}
218224

219-
export function execWithEnv(
220-
cmd: string,
221-
args: string[],
222-
env: { [varname: string]: string },
223-
stdin?: string,
224-
) {
225+
export function execWithEnv(cmd: string, args: string[], env: NodeJS.ProcessEnv, stdin?: string) {
225226
return _exec({ env, stdin }, cmd, args);
226227
}
227228

228229
export async function execAndCaptureError(
229230
cmd: string,
230231
args: string[],
231-
env?: { [varname: string]: string },
232+
env?: NodeJS.ProcessEnv,
232233
stdin?: string,
233234
): Promise<Error> {
234235
try {
@@ -243,7 +244,7 @@ export function execAndWaitForOutputToMatch(
243244
cmd: string,
244245
args: string[],
245246
match: RegExp,
246-
env?: { [varName: string]: string },
247+
env?: NodeJS.ProcessEnv,
247248
) {
248249
if (cmd === 'ng' && args[0] === 'serve') {
249250
// Accept matches up to 20 times after the initial match.

tests/legacy-cli/e2e/utils/project.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as fs from 'fs';
22
import * as path from 'path';
33
import { prerelease, SemVer } from 'semver';
4+
import yargsParser from 'yargs-parser';
45
import { packages } from '../../../../lib/packages';
56
import { getGlobalVariable } from './env';
67
import { prependToFile, readFile, replaceInFile, writeFile } from './fs';
@@ -25,9 +26,8 @@ export function updateTsConfig(fn: (json: any) => any | void) {
2526
export function ngServe(...args: string[]) {
2627
return execAndWaitForOutputToMatch('ng', ['serve', ...args], / Compiled successfully./);
2728
}
28-
29-
export async function prepareProjectForE2e(name) {
30-
const argv: string[] = getGlobalVariable('argv');
29+
export async function prepareProjectForE2e(name: string) {
30+
const argv: yargsParser.Arguments = getGlobalVariable('argv');
3131

3232
await git('config', 'user.email', '[email protected]');
3333
await git('config', 'user.name', 'Angular CLI E2e');
@@ -88,7 +88,7 @@ export function useSha() {
8888
return updateJsonFile('package.json', (json) => {
8989
// Install over the project with snapshot builds.
9090
function replaceDependencies(key: string) {
91-
const missingSnapshots = [];
91+
const missingSnapshots: string[] = [];
9292
Object.keys(json[key] || {})
9393
.filter((name) => name.match(/^@angular\//))
9494
.forEach((name) => {
@@ -229,5 +229,5 @@ export async function useCIChrome(projectDir: string = ''): Promise<void> {
229229
export const NgCLIVersion = new SemVer(packages['@angular/cli'].version);
230230

231231
export function isPrereleaseCli(): boolean {
232-
return prerelease(NgCLIVersion)?.length > 0;
232+
return (prerelease(NgCLIVersion)?.length ?? 0) > 0;
233233
}

0 commit comments

Comments
 (0)