Skip to content

Commit 7eea88b

Browse files
committed
feat(core): support TypeScript 4.4
Adds support for TypeScript 4.4. High-level overview of the changes made in this PR: * Bumps the various packages to `[email protected]` and `[email protected]`. * 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.
1 parent 95cfd0b commit 7eea88b

File tree

115 files changed

+400
-249
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

115 files changed

+400
-249
lines changed

Diff for: aio/aio-builds-setup/dockerbuild/scripts-js/lib/common/circle-ci-api.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -22,28 +22,28 @@ export interface BuildInfo {
2222
username: string;
2323
build_num: number;
2424
has_artifacts: boolean;
25-
outcome: string; // e.g. 'success'
26-
vcs_revision: string; // HEAD SHA
25+
outcome: string; // e.g. 'success'
26+
vcs_revision: string; // HEAD SHA
2727
// there are other fields but they are not used in this code
2828
}
2929

3030
/**
3131
* A Helper that can interact with the CircleCI API.
3232
*/
3333
export class CircleCiApi {
34-
3534
private tokenParam = `circle-token=${this.circleCiToken}`;
3635

3736
/**
3837
* Construct a helper that can interact with the CircleCI REST API.
39-
* @param githubOrg The Github organisation whose repos we want to access in CircleCI (e.g. angular).
38+
* @param githubOrg The Github organisation whose repos we want to access in CircleCI (e.g.
39+
* angular).
4040
* @param githubRepo The Github repo whose builds we want to access in CircleCI (e.g. angular).
4141
* @param circleCiToken The CircleCI API access token (secret).
4242
*/
4343
constructor(
44-
private githubOrg: string,
45-
private githubRepo: string,
46-
private circleCiToken: string,
44+
private githubOrg: string,
45+
private githubRepo: string,
46+
private circleCiToken: string,
4747
) {
4848
assertNotMissingOrEmpty('githubOrg', githubOrg);
4949
assertNotMissingOrEmpty('githubRepo', githubRepo);
@@ -64,7 +64,7 @@ export class CircleCiApi {
6464
}
6565
return response.json();
6666
} catch (error) {
67-
throw new Error(`CircleCI build info request failed (${error.message})`);
67+
throw new Error(`CircleCI build info request failed (${(error as Error).message})`);
6868
}
6969
}
7070

@@ -84,7 +84,7 @@ export class CircleCiApi {
8484
}
8585
return artifact.url;
8686
} catch (error) {
87-
throw new Error(`CircleCI artifact URL request failed (${error.message})`);
87+
throw new Error(`CircleCI artifact URL request failed (${(error as Error).message})`);
8888
}
8989
}
9090
}

Diff for: aio/aio-builds-setup/dockerbuild/scripts-js/lib/common/utils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export const getEnvVar = (name: string, isOptional = false): string => {
6666
try {
6767
throw new Error(`ERROR: Missing required environment variable '${name}'!`);
6868
} catch (error) {
69-
console.error(error.stack);
69+
console.error((error as Error).stack);
7070
process.exit(1);
7171
}
7272
}

Diff for: aio/aio-builds-setup/dockerbuild/scripts-js/lib/preview-server/build-retriever.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export class BuildRetriever {
6565
await promisify(fs.writeFile)(outPath, buffer);
6666
}
6767
return outPath;
68-
} catch (error) {
68+
} catch (error: any) {
6969
this.logger.warn(error);
7070
const status = (error.type === 'max-size') ? 413 : 500;
7171
throw new PreviewServerError(status, `CircleCI artifact download failed (${error.message || error})`);

Diff for: aio/aio-builds-setup/dockerbuild/scripts-js/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"shelljs": "^0.8.4",
3434
"source-map-support": "^0.5.19",
3535
"tar-stream": "^2.1.3",
36-
"tslib": "^2.2.0"
36+
"tslib": "^2.3.0"
3737
},
3838
"devDependencies": {
3939
"@types/body-parser": "^1.19.0",
@@ -49,6 +49,6 @@
4949
"supertest": "^4.0.2",
5050
"tslint": "^6.1.3",
5151
"tslint-jasmine-noSkipOrFocus": "^1.0.9",
52-
"typescript": "~4.3.4"
52+
"typescript": "~4.4.2"
5353
}
5454
}

Diff for: aio/aio-builds-setup/dockerbuild/scripts-js/test/preview-server/utils.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ describe('preview-server/utils', () => {
3737
originalUrl: 'some.domain.com/path',
3838
} as express.Request;
3939
throwRequestError(505, 'ERROR MESSAGE', request);
40-
} catch (error) {
40+
} catch (error: any) {
4141
caught = true;
4242
expect(error).toBeInstanceOf(PreviewServerError);
4343
expect(error.status).toEqual(505);

Diff for: aio/aio-builds-setup/dockerbuild/scripts-js/yarn.lock

+8-8
Original file line numberDiff line numberDiff line change
@@ -2505,10 +2505,10 @@ tslib@^1.8.1:
25052505
version "1.9.3"
25062506
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.9.3.tgz#d7e4dd79245d85428c4d7e4822a79917954ca286"
25072507

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

25132513
tslint-jasmine-noSkipOrFocus@^1.0.9:
25142514
version "1.0.9"
@@ -2563,10 +2563,10 @@ typedarray-to-buffer@^3.1.5:
25632563
dependencies:
25642564
is-typedarray "^1.0.0"
25652565

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

25712571
undefsafe@^2.0.2:
25722572
version "2.0.2"

Diff for: aio/content/examples/cli-builder/src/my-builder.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ async function copyFileBuilder(
2929
// #docregion builder
3030
return {
3131
success: false,
32-
error: err.message,
32+
error: (err as Error).message,
3333
};
3434
}
3535

Diff for: aio/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100
"@angular/service-worker": "12.1.1",
101101
"@webcomponents/custom-elements": "1.5.0",
102102
"rxjs": "^6.6.7",
103-
"tslib": "^2.2.0",
103+
"tslib": "^2.3.0",
104104
"zone.js": "~0.11.4"
105105
},
106106
"devDependencies": {
@@ -177,7 +177,7 @@
177177
"tree-kill": "^1.1.0",
178178
"ts-node": "^10.0.0",
179179
"tslint": "~6.1.3",
180-
"typescript": "~4.3.4",
180+
"typescript": "~4.4.2",
181181
"uglify-js": "^3.13.3",
182182
"unist-util-filter": "^2.0.3",
183183
"unist-util-source": "^3.0.0",

Diff for: aio/src/app/layout/doc-viewer/doc-viewer.component.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,8 @@ async function printSwDebugInfo(): Promise<void> {
294294
}
295295
console.log(await res.text());
296296
} catch (err) {
297-
console.log(`Failed to retrieve debug info from '/ngsw/state': ${err.message || err}`);
297+
console.log('Failed to retrieve debug info from \'/ngsw/state\': ' +
298+
(err as Error).message || err);
298299
}
299300
}
300301

Diff for: aio/tools/firebase-test-utils/FirebaseRedirectSource.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export class FirebaseRedirectSource {
4949

5050
return new FirebaseRedirectSource(`^${pattern}$`, restNamedGroups);
5151
} catch (err) {
52-
throw new Error(`Error in FirebaseRedirectSource: "${glob}" - ${err.message}`);
52+
throw new Error(`Error in FirebaseRedirectSource: "${glob}" - ${(err as Error).message}`);
5353
}
5454
}
5555

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

Diff for: aio/yarn.lock

+5-5
Original file line numberDiff line numberDiff line change
@@ -12711,7 +12711,7 @@ tslib@^1.10.0, tslib@^1.13.0, tslib@^1.8.1, tslib@^1.9.0:
1271112711
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00"
1271212712
integrity sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==
1271312713

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

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

1285812858
ua-parser-js@^0.7.28:
1285912859
version "0.7.28"

Diff for: integration/BUILD.bazel

+6
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,12 @@ INTEGRATION_TESTS = {
107107
# root @npm//typescript package.
108108
"pinned_npm_packages": ["typescript"],
109109
},
110+
"typings_test_ts44": {
111+
# Special case for `typings_test_ts44` test as we want to pin
112+
# `typescript` at version 4.4.x for that test and not link to the
113+
# root @npm//typescript package.
114+
"pinned_npm_packages": ["typescript"],
115+
},
110116
}
111117

112118
[

Diff for: integration/typings_test_ts44/include-all.ts

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
10+
11+
import * as animations from '@angular/animations';
12+
import * as animationsBrowser from '@angular/animations/browser';
13+
import * as animationsBrowserTesting from '@angular/animations/browser/testing';
14+
import * as common from '@angular/common';
15+
import * as commonHttp from '@angular/common/http';
16+
import * as commonTesting from '@angular/common/testing';
17+
import * as commonHttpTesting from '@angular/common/testing';
18+
import * as compiler from '@angular/compiler';
19+
import * as compilerTesting from '@angular/compiler/testing';
20+
import * as core from '@angular/core';
21+
import * as coreTesting from '@angular/core/testing';
22+
import * as elements from '@angular/elements';
23+
import * as forms from '@angular/forms';
24+
import * as platformBrowser from '@angular/platform-browser';
25+
import * as platformBrowserDynamic from '@angular/platform-browser-dynamic';
26+
import * as platformBrowserDynamicTesting from '@angular/platform-browser-dynamic/testing';
27+
import * as platformBrowserAnimations from '@angular/platform-browser/animations';
28+
import * as platformBrowserTesting from '@angular/platform-browser/testing';
29+
import * as platformServer from '@angular/platform-server';
30+
import * as platformServerInit from '@angular/platform-server/init';
31+
import * as platformServerTesting from '@angular/platform-server/testing';
32+
import * as router from '@angular/router';
33+
import * as routerTesting from '@angular/router/testing';
34+
import * as routerUpgrade from '@angular/router/upgrade';
35+
import * as serviceWorker from '@angular/service-worker';
36+
import * as upgrade from '@angular/upgrade';
37+
import * as upgradeStatic from '@angular/upgrade/static';
38+
import * as upgradeTesting from '@angular/upgrade/static/testing';
39+
40+
export default {
41+
animations,
42+
animationsBrowser,
43+
animationsBrowserTesting,
44+
common,
45+
commonTesting,
46+
commonHttp,
47+
commonHttpTesting,
48+
compiler,
49+
compilerTesting,
50+
core,
51+
coreTesting,
52+
elements,
53+
forms,
54+
platformBrowser,
55+
platformBrowserTesting,
56+
platformBrowserDynamic,
57+
platformBrowserDynamicTesting,
58+
platformBrowserAnimations,
59+
platformServer,
60+
platformServerInit,
61+
platformServerTesting,
62+
router,
63+
routerTesting,
64+
routerUpgrade,
65+
serviceWorker,
66+
upgrade,
67+
upgradeStatic,
68+
upgradeTesting,
69+
};

Diff for: integration/typings_test_ts44/package.json

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "angular-integration",
3+
"description": "Assert that users with TypeScript 4.4 can type-check an Angular application",
4+
"version": "0.0.0",
5+
"license": "MIT",
6+
"dependencies": {
7+
"@angular/animations": "file:../../dist/packages-dist/animations",
8+
"@angular/common": "file:../../dist/packages-dist/common",
9+
"@angular/compiler": "file:../../dist/packages-dist/compiler",
10+
"@angular/compiler-cli": "file:../../dist/packages-dist/compiler-cli",
11+
"@angular/core": "file:../../dist/packages-dist/core",
12+
"@angular/elements": "file:../../dist/packages-dist/elements",
13+
"@angular/forms": "file:../../dist/packages-dist/forms",
14+
"@angular/platform-browser": "file:../../dist/packages-dist/platform-browser",
15+
"@angular/platform-browser-dynamic": "file:../../dist/packages-dist/platform-browser-dynamic",
16+
"@angular/platform-server": "file:../../dist/packages-dist/platform-server",
17+
"@angular/router": "file:../../dist/packages-dist/router",
18+
"@angular/service-worker": "file:../../dist/packages-dist/service-worker",
19+
"@angular/upgrade": "file:../../dist/packages-dist/upgrade",
20+
"@types/jasmine": "file:../../node_modules/@types/jasmine",
21+
"rxjs": "file:../../node_modules/rxjs",
22+
"typescript": "4.4.2",
23+
"zone.js": "file:../../dist/zone.js-dist/archive/zone.js.tgz"
24+
},
25+
"scripts": {
26+
"test": "tsc"
27+
}
28+
}

Diff for: integration/typings_test_ts44/tsconfig.json

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"compilerOptions": {
3+
"forceConsistentCasingInFileNames": true,
4+
"strict": true,
5+
"noImplicitReturns": true,
6+
"noFallthroughCasesInSwitch": true,
7+
"experimentalDecorators": true,
8+
"module": "commonjs",
9+
"moduleResolution": "node",
10+
"outDir": "./dist/out-tsc",
11+
"rootDir": ".",
12+
"target": "es5",
13+
"lib": [
14+
"es5",
15+
"dom",
16+
"es2015.collection",
17+
"es2015.iterable",
18+
"es2015.promise"
19+
],
20+
"types": [],
21+
},
22+
"files": [
23+
"include-all.ts",
24+
"node_modules/@types/jasmine/index.d.ts"
25+
]
26+
}

Diff for: package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,9 @@
145145
"terser": "^4.4.0",
146146
"tmp": "0.2.1",
147147
"tsickle": "0.38.1",
148-
"tslib": "^2.2.0",
148+
"tslib": "^2.3.0",
149149
"tslint": "6.1.3",
150-
"typescript": "~4.3.4",
150+
"typescript": "~4.4.2",
151151
"xhr2": "0.2.1",
152152
"yargs": "^17.0.0"
153153
},

Diff for: packages/animations/browser/test/render/transition_animation_engine_spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ describe('TransitionAnimationEngine', () => {
633633
try {
634634
engine.flush();
635635
} catch (e) {
636-
errorMessage = e.toString();
636+
errorMessage = (e as Error).toString();
637637
}
638638

639639
expect(errorMessage).toMatch(/Unable to animate due to the following errors:/);

Diff for: packages/animations/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"node": "^12.14.1 || >=14.0.0"
99
},
1010
"dependencies": {
11-
"tslib": "^2.2.0"
11+
"tslib": "^2.3.0"
1212
},
1313
"peerDependencies": {
1414
"@angular/core": "0.0.0-PLACEHOLDER"

Diff for: packages/bazel/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@
2626
"@microsoft/api-extractor": "7.18.6",
2727
"shelljs": "0.8.4",
2828
"tsickle": "^0.38.0",
29-
"tslib": "^2.2.0"
29+
"tslib": "^2.3.0"
3030
},
3131
"peerDependencies": {
3232
"@angular/compiler-cli": "0.0.0-PLACEHOLDER",
3333
"@bazel/typescript": ">=1.0.0",
3434
"terser": "^4.3.1",
35-
"typescript": ">=4.2.3 <4.4",
35+
"typescript": ">=4.2.3 <4.5",
3636
"rollup": ">=1.20.0",
3737
"rollup-plugin-commonjs": ">=9.0.0",
3838
"rollup-plugin-node-resolve": ">=4.2.0",

0 commit comments

Comments
 (0)