Skip to content

Commit

Permalink
feat(core): support TypeScript 4.4
Browse files Browse the repository at this point in the history
Adds support for TypeScript 4.4. High-level overview of the changes made in this PR:

* Bumps the various packages to `typescript@4.4.2` and `tslib@2.3.0`.
* The error object in `catch` clauses is now typed as `unknown` which caused a lot of compilation errors. I've resolved it by casting either to `Error` or `any` depending on the use case. Note that I've been using `as` casts, rather than typing the object directly, because TS only allows for `any` or `unknown` to be used in the `catch` clause parameters.
* TS now passes in a third argument to the `__spreadArray` call inside child class constructors. I had to update a couple of places in the runtime and ngcc to be able to pick up the calls correctly.
* TS now generates code like `(0, foo)(arg1, arg2)` for imported function calls. I had to update a few of our tests to account for it. See microsoft/TypeScript#44624.
* Our `ngtsc` test setup calls the private `matchFiles` function from TS. I had to update our usage, because a new parameter was added.
* There was one place where we were setting the readonly `hasTrailingComma` property. I updated the usage to pass in the value when constructing the object instead.
* Some browser types were updated which meant that I had to resolve some trivial type errors.
* The downlevel decorators tranform was running into an issue where the Closure synthetic comments were being emitted twice. I've worked around it by recreating the class declaration node instead of cloning it.
  • Loading branch information
crisbeto committed Sep 6, 2021
1 parent 5472c28 commit 630f6c7
Show file tree
Hide file tree
Showing 115 changed files with 269 additions and 252 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export class CircleCiApi {
}
return response.json();
} catch (error) {
throw new Error(`CircleCI build info request failed (${error.message})`);
throw new Error(`CircleCI build info request failed (${(error as Error).message})`);
}
}

Expand All @@ -84,7 +84,7 @@ export class CircleCiApi {
}
return artifact.url;
} catch (error) {
throw new Error(`CircleCI artifact URL request failed (${error.message})`);
throw new Error(`CircleCI artifact URL request failed (${(error as Error).message})`);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export const getEnvVar = (name: string, isOptional = false): string => {
try {
throw new Error(`ERROR: Missing required environment variable '${name}'!`);
} catch (error) {
console.error(error.stack);
console.error((error as Error).stack);
process.exit(1);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export class BuildRetriever {
await promisify(fs.writeFile)(outPath, buffer);
}
return outPath;
} catch (error) {
} catch (error: any) {
this.logger.warn(error);
const status = (error.type === 'max-size') ? 413 : 500;
throw new PreviewServerError(status, `CircleCI artifact download failed (${error.message || error})`);
Expand Down
4 changes: 2 additions & 2 deletions aio/aio-builds-setup/dockerbuild/scripts-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"shelljs": "^0.8.4",
"source-map-support": "^0.5.19",
"tar-stream": "^2.1.3",
"tslib": "^2.2.0"
"tslib": "^2.3.0"
},
"devDependencies": {
"@types/body-parser": "^1.19.0",
Expand All @@ -49,6 +49,6 @@
"supertest": "^4.0.2",
"tslint": "^6.1.3",
"tslint-jasmine-noSkipOrFocus": "^1.0.9",
"typescript": "~4.3.4"
"typescript": "~4.4.2"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('preview-server/utils', () => {
originalUrl: 'some.domain.com/path',
} as express.Request;
throwRequestError(505, 'ERROR MESSAGE', request);
} catch (error) {
} catch (error: any) {
caught = true;
expect(error).toBeInstanceOf(PreviewServerError);
expect(error.status).toEqual(505);
Expand Down
16 changes: 8 additions & 8 deletions aio/aio-builds-setup/dockerbuild/scripts-js/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2505,10 +2505,10 @@ tslib@^1.8.1:
version "1.9.3"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.9.3.tgz#d7e4dd79245d85428c4d7e4822a79917954ca286"

tslib@^2.2.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.2.0.tgz#fb2c475977e35e241311ede2693cee1ec6698f5c"
integrity sha512-gS9GVHRU+RGn5KQM2rllAlR3dU6m7AcpJKdtH8gFvQiC4Otgk98XnmMU+nZenHt/+VhnBPWwgrJsyrdcw6i23w==
tslib@^2.3.0:
version "2.3.1"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.3.1.tgz#e8a335add5ceae51aa261d32a490158ef042ef01"
integrity sha512-77EbyPPpMz+FRFRuAFlWMtmgUWGe9UOG2Z25NqCwiIjRhOf5iKGuzSe5P2w1laq+FkRy4p+PCuVkJSGkzTEKVw==

tslint-jasmine-noSkipOrFocus@^1.0.9:
version "1.0.9"
Expand Down Expand Up @@ -2563,10 +2563,10 @@ typedarray-to-buffer@^3.1.5:
dependencies:
is-typedarray "^1.0.0"

typescript@~4.3.4:
version "4.3.4"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.3.4.tgz#3f85b986945bcf31071decdd96cf8bfa65f9dcbc"
integrity sha512-uauPG7XZn9F/mo+7MrsRjyvbxFpzemRjKEZXS4AK83oP2KKOJPvb+9cO/gmnv8arWZvhnjVOXz7B49m1l0e9Ew==
typescript@~4.4.2:
version "4.4.2"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.4.2.tgz#6d618640d430e3569a1dfb44f7d7e600ced3ee86"
integrity sha512-gzP+t5W4hdy4c+68bfcv0t400HVJMMd2+H9B7gae1nQlBzCqvrXX+6GL/b3GAgyTH966pzrZ70/fRjwAtZksSQ==

undefsafe@^2.0.2:
version "2.0.2"
Expand Down
2 changes: 1 addition & 1 deletion aio/content/examples/cli-builder/src/my-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ async function copyFileBuilder(
// #docregion builder
return {
success: false,
error: err.message,
error: (err as Error).message,
};
}

Expand Down
4 changes: 2 additions & 2 deletions aio/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
"@angular/service-worker": "12.1.1",
"@webcomponents/custom-elements": "1.5.0",
"rxjs": "^6.6.7",
"tslib": "^2.2.0",
"tslib": "^2.3.0",
"zone.js": "~0.11.4"
},
"devDependencies": {
Expand Down Expand Up @@ -177,7 +177,7 @@
"tree-kill": "^1.1.0",
"ts-node": "^10.0.0",
"tslint": "~6.1.3",
"typescript": "~4.3.4",
"typescript": "~4.4.2",
"uglify-js": "^3.13.3",
"unist-util-filter": "^2.0.3",
"unist-util-source": "^3.0.0",
Expand Down
3 changes: 2 additions & 1 deletion aio/src/app/layout/doc-viewer/doc-viewer.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,8 @@ async function printSwDebugInfo(): Promise<void> {
}
console.log(await res.text());
} catch (err) {
console.log(`Failed to retrieve debug info from '/ngsw/state': ${err.message || err}`);
console.log('Failed to retrieve debug info from \'/ngsw/state\': ' +
(err as Error).message || err);
}
}

Expand Down
4 changes: 2 additions & 2 deletions aio/tools/firebase-test-utils/FirebaseRedirectSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class FirebaseRedirectSource {

return new FirebaseRedirectSource(`^${pattern}$`, restNamedGroups);
} catch (err) {
throw new Error(`Error in FirebaseRedirectSource: "${glob}" - ${err.message}`);
throw new Error(`Error in FirebaseRedirectSource: "${glob}" - ${(err as Error).message}`);
}
}

Expand All @@ -72,7 +72,7 @@ export class FirebaseRedirectSource {
// capture groups.
return new FirebaseRedirectSource(regex.replace(/(\(\?)P(<[^>]+>)/g, '$1$2'));
} catch (err) {
throw new Error(`Error in FirebaseRedirectSource: "${regex}" - ${err.message}`);
throw new Error(`Error in FirebaseRedirectSource: "${regex}" - ${(err as Error).message}`);
}
}

Expand Down
10 changes: 5 additions & 5 deletions aio/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12711,7 +12711,7 @@ tslib@^1.10.0, tslib@^1.13.0, tslib@^1.8.1, tslib@^1.9.0:
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00"
integrity sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==

tslib@^2.0.0, tslib@^2.0.1, tslib@^2.2.0:
tslib@^2.0.0, tslib@^2.0.1, tslib@^2.2.0, tslib@^2.3.0:
version "2.3.1"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.3.1.tgz#e8a335add5ceae51aa261d32a490158ef042ef01"
integrity sha512-77EbyPPpMz+FRFRuAFlWMtmgUWGe9UOG2Z25NqCwiIjRhOf5iKGuzSe5P2w1laq+FkRy4p+PCuVkJSGkzTEKVw==
Expand Down Expand Up @@ -12850,10 +12850,10 @@ typescript@~3.2.2:
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.2.4.tgz#c585cb952912263d915b462726ce244ba510ef3d"
integrity sha512-0RNDbSdEokBeEAkgNbxJ+BLwSManFy9TeXz8uW+48j/xhEXv1ePME60olyzw2XzUqUBNAYFeJadIqAgNqIACwg==

typescript@~4.3.4:
version "4.3.5"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.3.5.tgz#4d1c37cc16e893973c45a06886b7113234f119f4"
integrity sha512-DqQgihaQ9cUrskJo9kIyW/+g0Vxsk8cDtZ52a3NGh0YNTfpUSArXSohyUGnvbPazEPLu398C0UxmKSOrPumUzA==
typescript@~4.4.2:
version "4.4.2"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.4.2.tgz#6d618640d430e3569a1dfb44f7d7e600ced3ee86"
integrity sha512-gzP+t5W4hdy4c+68bfcv0t400HVJMMd2+H9B7gae1nQlBzCqvrXX+6GL/b3GAgyTH966pzrZ70/fRjwAtZksSQ==

ua-parser-js@^0.7.28:
version "0.7.28"
Expand Down
12 changes: 6 additions & 6 deletions integration/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -95,18 +95,18 @@ INTEGRATION_TESTS = {
# root @npm//typescript package.
"pinned_npm_packages": ["typescript"],
},
"typings_test_ts42": {
# Special case for `typings_test_ts42` test as we want to pin
# `typescript` at version 4.2.x for that test and not link to the
# root @npm//typescript package.
"pinned_npm_packages": ["typescript"],
},
"typings_test_ts43": {
# Special case for `typings_test_ts43` test as we want to pin
# `typescript` at version 4.3.x for that test and not link to the
# root @npm//typescript package.
"pinned_npm_packages": ["typescript"],
},
"typings_test_ts44": {
# Special case for `typings_test_ts44` test as we want to pin
# `typescript` at version 4.4.x for that test and not link to the
# root @npm//typescript package.
"pinned_npm_packages": ["typescript"],
},
}

[
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angular-integration",
"description": "Assert that users with TypeScript 4.2 can type-check an Angular application",
"description": "Assert that users with TypeScript 4.4 can type-check an Angular application",
"version": "0.0.0",
"license": "MIT",
"dependencies": {
Expand All @@ -19,7 +19,7 @@
"@angular/upgrade": "file:../../dist/packages-dist/upgrade",
"@types/jasmine": "file:../../node_modules/@types/jasmine",
"rxjs": "file:../../node_modules/rxjs",
"typescript": "4.2.4",
"typescript": "4.4.2",
"zone.js": "file:../../dist/zone.js-dist/archive/zone.js.tgz"
},
"scripts": {
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,9 @@
"terser": "^4.4.0",
"tmp": "0.2.1",
"tsickle": "0.38.1",
"tslib": "^2.2.0",
"tslib": "^2.3.0",
"tslint": "6.1.3",
"typescript": "~4.3.4",
"typescript": "~4.4.2",
"xhr2": "0.2.1",
"yargs": "^17.0.0"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ describe('TransitionAnimationEngine', () => {
try {
engine.flush();
} catch (e) {
errorMessage = e.toString();
errorMessage = (e as Error).toString();
}

expect(errorMessage).toMatch(/Unable to animate due to the following errors:/);
Expand Down
2 changes: 1 addition & 1 deletion packages/animations/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"node": "^12.14.1 || >=14.0.0"
},
"dependencies": {
"tslib": "^2.2.0"
"tslib": "^2.3.0"
},
"peerDependencies": {
"@angular/core": "0.0.0-PLACEHOLDER"
Expand Down
4 changes: 2 additions & 2 deletions packages/bazel/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@
"@microsoft/api-extractor": "7.18.6",
"shelljs": "0.8.4",
"tsickle": "^0.38.0",
"tslib": "^2.2.0"
"tslib": "^2.3.0"
},
"peerDependencies": {
"@angular/compiler-cli": "0.0.0-PLACEHOLDER",
"@bazel/typescript": ">=1.0.0",
"terser": "^4.3.1",
"typescript": ">=4.2.3 <4.4",
"typescript": ">=4.2.3 <4.5",
"rollup": ">=1.20.0",
"rollup-plugin-commonjs": ">=9.0.0",
"rollup-plugin-node-resolve": ">=4.2.0",
Expand Down
6 changes: 3 additions & 3 deletions packages/common/http/testing/test/request_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('HttpClient TestRequest', () => {
mock.expectOne('/some-url').flush(null);
fail();
} catch (error) {
expect(error.message)
expect((error as Error).message)
.toBe(
'Expected one matching request for criteria "Match URL: /some-url", found none.' +
' Requests received are: GET /some-other-url.');
Expand All @@ -61,7 +61,7 @@ describe('HttpClient TestRequest', () => {
mock.expectOne('/some-url?query=world').flush(null);
fail();
} catch (error) {
expect(error.message)
expect((error as Error).message)
.toBe(
'Expected one matching request for criteria "Match URL: /some-url?query=world", found none.' +
' Requests received are: GET /some-url?query=hello.');
Expand All @@ -85,7 +85,7 @@ describe('HttpClient TestRequest', () => {
mock.expectOne('/some-url').flush(null);
fail();
} catch (error) {
expect(error.message)
expect((error as Error).message)
.toBe(
'Expected one matching request for criteria "Match URL: /some-url", found none.' +
' Requests received are: GET /some-other-url?query=world, POST /and-another-url.');
Expand Down
2 changes: 1 addition & 1 deletion packages/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"locales": "locales",
"dependencies": {
"tslib": "^2.2.0"
"tslib": "^2.3.0"
},
"peerDependencies": {
"@angular/core": "0.0.0-PLACEHOLDER",
Expand Down
4 changes: 2 additions & 2 deletions packages/common/src/pipes/date_pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {invalidPipeArgumentError} from './invalid_pipe_argument_error';
* @description
*
* Formats a date value according to locale rules.
*
*
* `DatePipe` is executed only when it detects a pure change to the input value.
* A pure change is either a change to a primitive input value
* (such as `String`, `Number`, `Boolean`, or `Symbol`),
Expand Down Expand Up @@ -195,7 +195,7 @@ export class DatePipe implements PipeTransform {
try {
return formatDate(value, format, locale || this.locale, timezone);
} catch (error) {
throw invalidPipeArgumentError(DatePipe, error.message);
throw invalidPipeArgumentError(DatePipe, (error as Error).message);
}
}
}
6 changes: 3 additions & 3 deletions packages/common/src/pipes/number_pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export class DecimalPipe implements PipeTransform {
const num = strToNumber(value);
return formatNumber(num, locale, digitsInfo);
} catch (error) {
throw invalidPipeArgumentError(DecimalPipe, error.message);
throw invalidPipeArgumentError(DecimalPipe, (error as Error).message);
}
}
}
Expand Down Expand Up @@ -156,7 +156,7 @@ export class PercentPipe implements PipeTransform {
const num = strToNumber(value);
return formatPercent(num, locale, digitsInfo);
} catch (error) {
throw invalidPipeArgumentError(PercentPipe, error.message);
throw invalidPipeArgumentError(PercentPipe, (error as Error).message);
}
}
}
Expand Down Expand Up @@ -281,7 +281,7 @@ export class CurrencyPipe implements PipeTransform {
const num = strToNumber(value);
return formatCurrency(num, locale, currency, currencyCode, digitsInfo);
} catch (error) {
throw invalidPipeArgumentError(CurrencyPipe, error.message);
throw invalidPipeArgumentError(CurrencyPipe, (error as Error).message);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/common/upgrade/src/location_shim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ export class $locationShim {
try {
fn(url, state, oldUrl, oldState);
} catch (e) {
err(e);
err(e as Error);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export function createEs2015LinkerPlugin({fileSystem, logger, ...options}: Linke
call.replaceWith(replacement);
} catch (e) {
const node = isFatalLinkerError(e) ? e.node as t.Node : call.node;
throw buildCodeFrameError(call.hub.file, e.message, node);
throw buildCodeFrameError(call.hub.file, (e as Error).message, node);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/compiler-cli/ngcc/main-ngcc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ if (require.main === module) {
options.logger.debug(`Run ngcc in ${duration}s.`);
}
process.exitCode = 0;
} catch (e) {
} catch (e: any) {
console.error(e.stack || e.message);
process.exit(typeof e.code === 'number' ? e.code : 1);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/compiler-cli/ngcc/src/execution/cluster/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ if (require.main === module) {
await startWorker(logger, createCompileFn);
process.exitCode = 0;
} catch (e) {
console.error(e.stack || e.message);
console.error((e as Error).stack || (e as Error).message);
process.exit(1);
}
})();
Expand Down Expand Up @@ -79,7 +79,7 @@ export async function startWorker(logger: Logger, createCompileFn: CreateCompile
throw new Error(
`[Worker #${cluster.worker.id}] Invalid message received: ${JSON.stringify(msg)}`);
}
} catch (err) {
} catch (err: any) {
switch (err && err.code) {
case 'ENOMEM':
// Not being able to allocate enough memory is not necessarily a problem with processing
Expand Down
Loading

0 comments on commit 630f6c7

Please sign in to comment.