Skip to content

Commit cf2f917

Browse files
committed
build: fix typescript compilation errors
1 parent 675a7f6 commit cf2f917

21 files changed

+58
-47
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 { npm } 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 npm(
88
'run',
99
'admin',

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-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export default async function () {
1717
process.chdir(argv.reuse);
1818
await gitClean();
1919
} else {
20-
const extraArgs = [];
20+
const extraArgs: string[] = [];
2121
const testRegistry = getGlobalVariable('package-registry');
2222
const isCI = getGlobalVariable('ci');
2323

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

+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/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]: RegExp | 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/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
@@ -19,7 +19,7 @@ export default async function () {
1919

2020
const currentDirectory = process.cwd();
2121

22-
const extraArgs = [];
22+
const extraArgs: string[] = [];
2323
if (isPrereleaseCli()) {
2424
extraArgs.push('--next');
2525
}

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
@@ -30,7 +30,7 @@ export function symlinkFile(from: string, to: string, type?: string): Promise<vo
3030
}
3131

3232
export function createDir(path: string): Promise<string> {
33-
return fs.mkdir(path, { recursive: true });
33+
return fs.mkdir(path, { recursive: true }) as Promise<string>;
3434
}
3535

3636
export async function copyFile(from: string, to: string): Promise<void> {

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

+19-13
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const treeKill = require('tree-kill');
1010
interface ExecOptions {
1111
silent?: boolean;
1212
waitForMatch?: RegExp;
13-
env?: { [varname: string]: string };
13+
env?: { [varname: string]: string | undefined };
1414
stdin?: string;
1515
}
1616

@@ -58,7 +58,8 @@ function _exec(options: ExecOptions, cmd: string, args: string[]): Promise<Proce
5858
}
5959

6060
const childProcess = child_process.spawn(cmd, args, spawnOptions);
61-
childProcess.stdout.on('data', (data: Buffer) => {
61+
// @ts-ignore
62+
childProcess.stdout!.on('data', (data: Buffer) => {
6263
stdout += data.toString('utf-8');
6364
if (options.silent) {
6465
return;
@@ -69,7 +70,8 @@ function _exec(options: ExecOptions, cmd: string, args: string[]): Promise<Proce
6970
.filter((line) => line !== '')
7071
.forEach((line) => console.log(' ' + line));
7172
});
72-
childProcess.stderr.on('data', (data: Buffer) => {
73+
// @ts-ignore
74+
childProcess.stderr!.on('data', (data: Buffer) => {
7375
stderr += data.toString('utf-8');
7476
if (options.silent) {
7577
return;
@@ -109,19 +111,21 @@ function _exec(options: ExecOptions, cmd: string, args: string[]): Promise<Proce
109111
);
110112
});
111113
childProcess.on('error', (error) => {
112-
err.message += `${error}...\n\nSTDOUT:\n${stdout}\n\nSTDERR:\n${stderr}\n`;
113-
reject(err);
114+
error.message += `${error}...\n\nSTDOUT:\n${stdout}\n\nSTDERR:\n${stderr}\n`;
115+
reject(error);
114116
});
115117

116118
if (options.waitForMatch) {
117119
const match = options.waitForMatch;
118-
childProcess.stdout.on('data', (data: Buffer) => {
120+
// @ts-ignore
121+
childProcess.stdout!.on('data', (data: Buffer) => {
119122
if (data.toString().match(match)) {
120123
resolve({ stdout, stderr });
121124
matched = true;
122125
}
123126
});
124-
childProcess.stderr.on('data', (data: Buffer) => {
127+
// @ts-ignore
128+
childProcess.stderr!.on('data', (data: Buffer) => {
125129
if (data.toString().match(match)) {
126130
resolve({ stdout, stderr });
127131
matched = true;
@@ -131,8 +135,8 @@ function _exec(options: ExecOptions, cmd: string, args: string[]): Promise<Proce
131135

132136
// Provide input to stdin if given.
133137
if (options.stdin) {
134-
childProcess.stdin.write(options.stdin);
135-
childProcess.stdin.end();
138+
childProcess.stdin!.write(options.stdin);
139+
childProcess.stdin!.end();
136140
}
137141
});
138142
}
@@ -154,13 +158,15 @@ export function waitForAnyProcessOutputToMatch(
154158
new Promise((resolve) => {
155159
let stdout = '';
156160
let stderr = '';
157-
childProcess.stdout.on('data', (data: Buffer) => {
161+
// @ts-ignore
162+
childProcess.stdout!.on('data', (data: Buffer) => {
158163
stdout += data.toString();
159164
if (data.toString().match(match)) {
160165
resolve({ stdout, stderr });
161166
}
162167
});
163-
childProcess.stderr.on('data', (data: Buffer) => {
168+
// @ts-ignore
169+
childProcess.stderr!.on('data', (data: Buffer) => {
164170
stderr += data.toString();
165171
if (data.toString().match(match)) {
166172
resolve({ stdout, stderr });
@@ -188,7 +194,7 @@ export function silentExec(cmd: string, ...args: string[]) {
188194
export function execWithEnv(
189195
cmd: string,
190196
args: string[],
191-
env: { [varname: string]: string },
197+
env: { [varname: string]: string | undefined },
192198
stdin?: string,
193199
) {
194200
return _exec({ env, stdin }, cmd, args);
@@ -197,7 +203,7 @@ export function execWithEnv(
197203
export async function execAndCaptureError(
198204
cmd: string,
199205
args: string[],
200-
env?: { [varname: string]: string },
206+
env?: { [varname: string]: string | undefined },
201207
stdin?: string,
202208
): Promise<Error> {
203209
try {

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');
@@ -87,7 +87,7 @@ export function useSha() {
8787
return updateJsonFile('package.json', (json) => {
8888
// Install over the project with snapshot builds.
8989
function replaceDependencies(key: string) {
90-
const missingSnapshots = [];
90+
const missingSnapshots: string[] = [];
9191
Object.keys(json[key] || {})
9292
.filter((name) => name.match(/^@angular\//))
9393
.forEach((name) => {
@@ -228,5 +228,5 @@ export async function useCIChrome(projectDir: string = ''): Promise<void> {
228228
export const NgCLIVersion = new SemVer(packages['@angular/cli'].version);
229229

230230
export function isPrereleaseCli(): boolean {
231-
return prerelease(NgCLIVersion)?.length > 0;
231+
return (prerelease(NgCLIVersion)?.length ?? 0) > 0;
232232
}

tests/legacy-cli/e2e_runner.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ function lastLogger() {
7272
}
7373

7474
const testGlob = argv.glob || 'tests/**/*.ts';
75-
let currentFileName = null;
75+
let currentFileName = '';
7676

7777
const e2eRoot = path.join(__dirname, 'e2e');
7878
const allSetups = glob.sync('setup/**/*.ts', { nodir: true, cwd: e2eRoot }).sort();
@@ -159,7 +159,7 @@ Promise.all([findFreePort(), findFreePort()])
159159
};
160160

161161
let clean = true;
162-
let previousDir = null;
162+
let previousDir: string | null = null;
163163

164164
return Promise.resolve()
165165
.then(() => printHeader(currentFileName, testIndex))

0 commit comments

Comments
 (0)