Skip to content

Commit 8523d25

Browse files
committed
build: fix typescript compilation errors
1 parent b79b0f0 commit 8523d25

22 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 { execWithEnv } 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-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/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
@@ -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

+18-12
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
cwd?: string;
1616
}
@@ -59,7 +59,8 @@ function _exec(options: ExecOptions, cmd: string, args: string[]): Promise<Proce
5959
}
6060

6161
const childProcess = child_process.spawn(cmd, args, spawnOptions);
62-
childProcess.stdout.on('data', (data: Buffer) => {
62+
// @ts-ignore
63+
childProcess.stdout!.on('data', (data: Buffer) => {
6364
stdout += data.toString('utf-8');
6465
if (options.silent) {
6566
return;
@@ -70,7 +71,8 @@ function _exec(options: ExecOptions, cmd: string, args: string[]): Promise<Proce
7071
.filter((line) => line !== '')
7172
.forEach((line) => console.log(' ' + line));
7273
});
73-
childProcess.stderr.on('data', (data: Buffer) => {
74+
// @ts-ignore
75+
childProcess.stderr!.on('data', (data: Buffer) => {
7476
stderr += data.toString('utf-8');
7577
if (options.silent) {
7678
return;
@@ -116,13 +118,15 @@ function _exec(options: ExecOptions, cmd: string, args: string[]): Promise<Proce
116118

117119
if (options.waitForMatch) {
118120
const match = options.waitForMatch;
119-
childProcess.stdout.on('data', (data: Buffer) => {
121+
// @ts-ignore
122+
childProcess.stdout!.on('data', (data: Buffer) => {
120123
if (data.toString().match(match)) {
121124
resolve({ stdout, stderr });
122125
matched = true;
123126
}
124127
});
125-
childProcess.stderr.on('data', (data: Buffer) => {
128+
// @ts-ignore
129+
childProcess.stderr!.on('data', (data: Buffer) => {
126130
if (data.toString().match(match)) {
127131
resolve({ stdout, stderr });
128132
matched = true;
@@ -132,8 +136,8 @@ function _exec(options: ExecOptions, cmd: string, args: string[]): Promise<Proce
132136

133137
// Provide input to stdin if given.
134138
if (options.stdin) {
135-
childProcess.stdin.write(options.stdin);
136-
childProcess.stdin.end();
139+
childProcess.stdin!.write(options.stdin);
140+
childProcess.stdin!.end();
137141
}
138142
});
139143
}
@@ -155,13 +159,15 @@ export function waitForAnyProcessOutputToMatch(
155159
new Promise((resolve) => {
156160
let stdout = '';
157161
let stderr = '';
158-
childProcess.stdout.on('data', (data: Buffer) => {
162+
// @ts-ignore
163+
childProcess.stdout!.on('data', (data: Buffer) => {
159164
stdout += data.toString();
160165
if (data.toString().match(match)) {
161166
resolve({ stdout, stderr });
162167
}
163168
});
164-
childProcess.stderr.on('data', (data: Buffer) => {
169+
// @ts-ignore
170+
childProcess.stderr!.on('data', (data: Buffer) => {
165171
stderr += data.toString();
166172
if (data.toString().match(match)) {
167173
resolve({ stdout, stderr });
@@ -189,7 +195,7 @@ export function silentExec(cmd: string, ...args: string[]) {
189195
export function execWithEnv(
190196
cmd: string,
191197
args: string[],
192-
env: { [varname: string]: string },
198+
env: { [varname: string]: string | undefined },
193199
stdin?: string,
194200
) {
195201
return _exec({ env, stdin }, cmd, args);
@@ -198,7 +204,7 @@ export function execWithEnv(
198204
export async function execAndCaptureError(
199205
cmd: string,
200206
args: string[],
201-
env?: { [varname: string]: string },
207+
env?: { [varname: string]: string | undefined },
202208
stdin?: string,
203209
): Promise<Error> {
204210
try {
@@ -213,7 +219,7 @@ export function execAndWaitForOutputToMatch(
213219
cmd: string,
214220
args: string[],
215221
match: RegExp,
216-
env?: { [varName: string]: string },
222+
env?: { [varName: string]: string | undefined },
217223
) {
218224
if (cmd === 'ng' && args[0] === 'serve') {
219225
// 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');
@@ -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)