Skip to content

Commit

Permalink
feat(core): support TypeScript 4.7
Browse files Browse the repository at this point in the history
Adds support for TypeScript 4.7. Changes include:
* Bumping the TS version as well as some Bazel dependencies to include bazel-contrib/rules_nodejs#3420.
* Adding a backwards-compatibility layer for calls to `updateTypeParameterDeclaration`.
* Making `LView` generic in order to make it easier to type the context based on the usage. Currently the context can be 4 different types which coupled with stricter type checking would required a lot of extra casting all over `core`.
* Fixing a bunch of miscellaneous type errors.
* Removing assertions of `ReferenceEntry.isDefinition` in a few of the language service tests. The field isn't returned by TS anymore and we weren't using it for anything.
* Resolving in error in the language service that was caused by TS attempting to parse HTML files when we try to open them. Previous TS was silently setting them as `ScriptKind.Unknown` and ignoring the errors, but now it throws. I've worked around it by setting them as `ScriptKind.JSX`.
  • Loading branch information
crisbeto committed Apr 29, 2022
1 parent d4fc12f commit 010f3b3
Show file tree
Hide file tree
Showing 48 changed files with 419 additions and 176 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ export const diff = <T>(differ: DefaultIterableDiffer<T>, a: T[], b: T[]):
if (!alreadySet[record.previousIndex]) {
a[record.currentIndex] = a[record.previousIndex];
} else {
a[record.currentIndex] = {} as T;
a[record.currentIndex] = {} as unknown as T;
}
Object.keys(b[record.currentIndex]).forEach(prop => {
Object.keys(b[record.currentIndex] as unknown as {}).forEach(prop => {
// TypeScript's type inference didn't follow the check from above.
if (record.currentIndex === null) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const initializeExtendedWindowOperations = () => {
extendWindowOperations(window, {inspectedApplication: chromeWindowExtensions});
};

const extendWindowOperations = <T>(target, classImpl: T) => {
const extendWindowOperations = <T extends {}>(target, classImpl: T) => {
for (const key of Object.keys(classImpl)) {
if (target[key] != null) {
console.warn(`A window function or object named ${key} would be overwritten`);
Expand Down
3 changes: 1 addition & 2 deletions goldens/public-api/core/global_utils.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export interface DirectiveDebugMetadata {
export function getComponent<T>(element: Element): T | null;

// @public
export function getContext<T>(element: Element): T | null;
export function getContext<T extends ({} | RootContext)>(element: Element): T | null;

// @public
export function getDirectiveMetadata(directiveOrComponentInstance: any): ComponentDebugMetadata | DirectiveDebugMetadata | null;
Expand Down Expand Up @@ -59,7 +59,6 @@ export interface Listener {
useCapture: boolean;
}


// (No @packageDocumentation comment for this package)

```
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
"@angular/compiler-cli": "file:../../../dist/packages-dist/compiler-cli",
"@babel/core": "^7.16.0",
"@bazel/bazelisk": "file:../../../node_modules/@bazel/bazelisk",
"@bazel/concatjs": "5.4.0",
"@bazel/esbuild": "5.4.0",
"@bazel/protractor": "5.4.0",
"@bazel/rollup": "5.4.0",
"@bazel/terser": "5.4.0",
"@bazel/concatjs": "5.4.1",
"@bazel/esbuild": "5.4.1",
"@bazel/protractor": "5.4.1",
"@bazel/rollup": "5.4.1",
"@bazel/terser": "5.4.1",
"@rollup/plugin-commonjs": "file:../../../node_modules/@rollup/plugin-commonjs",
"@rollup/plugin-node-resolve": "file:../../../node_modules/@rollup/plugin-node-resolve",
"@types/jasmine": "2.8.8",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,10 +265,10 @@
"@bazel/bazelisk@file:../../../node_modules/@bazel/bazelisk":
version "1.11.0"

"@bazel/[email protected].0":
version "5.4.0"
resolved "https://registry.yarnpkg.com/@bazel/concatjs/-/concatjs-5.4.0.tgz#04e752a6ea3e684f00879e6683657c4ede72df6e"
integrity sha512-jlupaDKxqFS3B1lttOIgkKxirP7v5Qx7KCFtOXO7JxtvYJD/qKtKXEQggTrGKJqLPyiZlNiYimHHGICLSWIZcQ==
"@bazel/[email protected].1":
version "5.4.1"
resolved "https://registry.yarnpkg.com/@bazel/concatjs/-/concatjs-5.4.1.tgz#590b7944d89136863ba4e3e264c555b0efc815de"
integrity sha512-E5lVBdJNeTcXgDM4phmY2JbHdwWIJZ61ls22McXpWhsDlfItURhNuzxbg/+8gDDX0AlMsJnBpAtFLNVH5c2xwA==
dependencies:
protobufjs "6.8.8"
source-map-support "0.5.9"
Expand Down
5 changes: 5 additions & 0 deletions integration/nodenext_resolution/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
load("//integration:index.bzl", "ng_integration_test")

ng_integration_test(
name = "test",
)
73 changes: 73 additions & 0 deletions integration/nodenext_resolution/include-all.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/



import * as animations from '@angular/animations';
import * as animationsBrowser from '@angular/animations/browser';
import * as animationsBrowserTesting from '@angular/animations/browser/testing';
import * as common from '@angular/common';
import * as commonHttp from '@angular/common/http';
import * as commonTesting from '@angular/common/testing';
import * as commonHttpTesting from '@angular/common/testing';
import * as compiler from '@angular/compiler';
import * as compilerCli from '@angular/compiler-cli';
import * as compilerTesting from '@angular/compiler/testing';
import * as core from '@angular/core';
import * as coreTesting from '@angular/core/testing';
import * as elements from '@angular/elements';
import * as forms from '@angular/forms';
import * as localize from '@angular/localize';
import * as platformBrowser from '@angular/platform-browser';
import * as platformBrowserDynamic from '@angular/platform-browser-dynamic';
import * as platformBrowserDynamicTesting from '@angular/platform-browser-dynamic/testing';
import * as platformBrowserAnimations from '@angular/platform-browser/animations';
import * as platformBrowserTesting from '@angular/platform-browser/testing';
import * as platformServer from '@angular/platform-server';
import * as platformServerInit from '@angular/platform-server/init';
import * as platformServerTesting from '@angular/platform-server/testing';
import * as router from '@angular/router';
import * as routerTesting from '@angular/router/testing';
import * as routerUpgrade from '@angular/router/upgrade';
import * as serviceWorker from '@angular/service-worker';
import * as upgrade from '@angular/upgrade';
import * as upgradeStatic from '@angular/upgrade/static';
import * as upgradeTesting from '@angular/upgrade/static/testing';

export default {
animations,
animationsBrowser,
animationsBrowserTesting,
common,
commonTesting,
commonHttp,
commonHttpTesting,
compiler,
compilerTesting,
compilerCli,
core,
coreTesting,
elements,
forms,
localize,
platformBrowser,
platformBrowserTesting,
platformBrowserDynamic,
platformBrowserDynamicTesting,
platformBrowserAnimations,
platformServer,
platformServerInit,
platformServerTesting,
router,
routerTesting,
routerUpgrade,
serviceWorker,
upgrade,
upgradeStatic,
upgradeTesting,
};
29 changes: 29 additions & 0 deletions integration/nodenext_resolution/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "angular-integration",
"description": "Assert that users with module: nodenext in their tsconfig can import our packages",
"version": "0.0.0",
"license": "MIT",
"dependencies": {
"@angular/animations": "file:../../dist/packages-dist/animations",
"@angular/common": "file:../../dist/packages-dist/common",
"@angular/compiler": "file:../../dist/packages-dist/compiler",
"@angular/compiler-cli": "file:../../dist/packages-dist/compiler-cli",
"@angular/core": "file:../../dist/packages-dist/core",
"@angular/elements": "file:../../dist/packages-dist/elements",
"@angular/forms": "file:../../dist/packages-dist/forms",
"@angular/localize": "file:../../dist/packages-dist/localize",
"@angular/platform-browser": "file:../../dist/packages-dist/platform-browser",
"@angular/platform-browser-dynamic": "file:../../dist/packages-dist/platform-browser-dynamic",
"@angular/platform-server": "file:../../dist/packages-dist/platform-server",
"@angular/router": "file:../../dist/packages-dist/router",
"@angular/service-worker": "file:../../dist/packages-dist/service-worker",
"@angular/upgrade": "file:../../dist/packages-dist/upgrade",
"@types/jasmine": "file:../../node_modules/@types/jasmine",
"rxjs": "file:../../node_modules/rxjs",
"typescript": "file:../../node_modules/typescript",
"zone.js": "file:../../dist/zone.js-dist/archive/zone.js.tgz"
},
"scripts": {
"test": "tsc"
}
}
26 changes: 26 additions & 0 deletions integration/nodenext_resolution/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"compilerOptions": {
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"experimentalDecorators": true,
"module": "NodeNext",
"moduleResolution": "node",
"outDir": "./dist/out-tsc",
"rootDir": ".",
"target": "es5",
"lib": [
"es5",
"dom",
"es2015.collection",
"es2015.iterable",
"es2015.promise"
],
"types": [],
},
"files": [
"include-all.ts",
"node_modules/@types/jasmine/index.d.ts"
]
}
9 changes: 9 additions & 0 deletions integration/typings_test_ts47/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
load("//integration:index.bzl", "ng_integration_test")

ng_integration_test(
name = "test",
# Special case for `typings_test_ts47` test as we want to pin
# `typescript` at version 4.7.x for that test and not link to the
# root @npm//typescript package.
pinned_npm_packages = ["typescript"],
)
71 changes: 71 additions & 0 deletions integration/typings_test_ts47/include-all.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/



import * as animations from '@angular/animations';
import * as animationsBrowser from '@angular/animations/browser';
import * as animationsBrowserTesting from '@angular/animations/browser/testing';
import * as common from '@angular/common';
import * as commonHttp from '@angular/common/http';
import * as commonTesting from '@angular/common/testing';
import * as commonHttpTesting from '@angular/common/testing';
import * as compiler from '@angular/compiler';
import * as compilerTesting from '@angular/compiler/testing';
import * as core from '@angular/core';
import * as coreTesting from '@angular/core/testing';
import * as elements from '@angular/elements';
import * as forms from '@angular/forms';
import * as localize from '@angular/localize';
import * as platformBrowser from '@angular/platform-browser';
import * as platformBrowserDynamic from '@angular/platform-browser-dynamic';
import * as platformBrowserDynamicTesting from '@angular/platform-browser-dynamic/testing';
import * as platformBrowserAnimations from '@angular/platform-browser/animations';
import * as platformBrowserTesting from '@angular/platform-browser/testing';
import * as platformServer from '@angular/platform-server';
import * as platformServerInit from '@angular/platform-server/init';
import * as platformServerTesting from '@angular/platform-server/testing';
import * as router from '@angular/router';
import * as routerTesting from '@angular/router/testing';
import * as routerUpgrade from '@angular/router/upgrade';
import * as serviceWorker from '@angular/service-worker';
import * as upgrade from '@angular/upgrade';
import * as upgradeStatic from '@angular/upgrade/static';
import * as upgradeTesting from '@angular/upgrade/static/testing';

export default {
animations,
animationsBrowser,
animationsBrowserTesting,
common,
commonTesting,
commonHttp,
commonHttpTesting,
compiler,
compilerTesting,
core,
coreTesting,
elements,
forms,
localize,
platformBrowser,
platformBrowserTesting,
platformBrowserDynamic,
platformBrowserDynamicTesting,
platformBrowserAnimations,
platformServer,
platformServerInit,
platformServerTesting,
router,
routerTesting,
routerUpgrade,
serviceWorker,
upgrade,
upgradeStatic,
upgradeTesting,
};
29 changes: 29 additions & 0 deletions integration/typings_test_ts47/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "angular-integration",
"description": "Assert that users with TypeScript 4.7 can type-check an Angular application",
"version": "0.0.0",
"license": "MIT",
"dependencies": {
"@angular/animations": "file:../../dist/packages-dist/animations",
"@angular/common": "file:../../dist/packages-dist/common",
"@angular/compiler": "file:../../dist/packages-dist/compiler",
"@angular/compiler-cli": "file:../../dist/packages-dist/compiler-cli",
"@angular/core": "file:../../dist/packages-dist/core",
"@angular/elements": "file:../../dist/packages-dist/elements",
"@angular/forms": "file:../../dist/packages-dist/forms",
"@angular/localize": "file:../../dist/packages-dist/localize",
"@angular/platform-browser": "file:../../dist/packages-dist/platform-browser",
"@angular/platform-browser-dynamic": "file:../../dist/packages-dist/platform-browser-dynamic",
"@angular/platform-server": "file:../../dist/packages-dist/platform-server",
"@angular/router": "file:../../dist/packages-dist/router",
"@angular/service-worker": "file:../../dist/packages-dist/service-worker",
"@angular/upgrade": "file:../../dist/packages-dist/upgrade",
"@types/jasmine": "file:../../node_modules/@types/jasmine",
"rxjs": "file:../../node_modules/rxjs",
"typescript": "4.7.0-beta",
"zone.js": "file:../../dist/zone.js-dist/archive/zone.js.tgz"
},
"scripts": {
"test": "tsc"
}
}
26 changes: 26 additions & 0 deletions integration/typings_test_ts47/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"compilerOptions": {
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"experimentalDecorators": true,
"module": "commonjs",
"moduleResolution": "node",
"outDir": "./dist/out-tsc",
"rootDir": ".",
"target": "es5",
"lib": [
"es5",
"dom",
"es2015.collection",
"es2015.iterable",
"es2015.promise"
],
"types": [],
},
"files": [
"include-all.ts",
"node_modules/@types/jasmine/index.d.ts"
]
}
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@
"@babel/template": "7.16.7",
"@babel/traverse": "7.17.9",
"@babel/types": "7.17.0",
"@bazel/concatjs": "5.4.0",
"@bazel/esbuild": "5.4.0",
"@bazel/jasmine": "5.4.0",
"@bazel/protractor": "5.4.0",
"@bazel/rollup": "5.4.0",
"@bazel/runfiles": "5.4.0",
"@bazel/terser": "5.4.0",
"@bazel/concatjs": "5.4.1",
"@bazel/esbuild": "5.4.1",
"@bazel/jasmine": "5.4.1",
"@bazel/protractor": "5.4.1",
"@bazel/rollup": "5.4.1",
"@bazel/runfiles": "5.4.1",
"@bazel/terser": "5.4.1",
"@microsoft/api-extractor": "7.22.2",
"@rollup/plugin-babel": "^5.3.0",
"@rollup/plugin-commonjs": "^21.0.0",
Expand Down Expand Up @@ -170,7 +170,7 @@
"tsickle": "0.38.1",
"tslib": "^2.3.0",
"tslint": "6.1.3",
"typescript": "~4.6.2",
"typescript": "4.7.0-beta",
"webtreemap": "^2.0.1",
"xhr2": "0.2.1",
"yargs": "^17.2.1"
Expand Down
2 changes: 1 addition & 1 deletion packages/bazel/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"rollup": "^2.56.3",
"rollup-plugin-sourcemaps": "^0.6.3",
"terser": "^5.9.0",
"typescript": ">=4.6.2 <4.7"
"typescript": ">=4.6.2 <4.8"
},
"peerDependenciesMeta": {
"terser": {
Expand Down
4 changes: 2 additions & 2 deletions packages/compiler-cli/ngcc/test/helpers/spy_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ export const spyProperty = <T, P extends keyof T>(ctx: T, prop: P): IPropertySpy

let value = ctx[prop];
const setMockValue = (mockValue: typeof value) => value = mockValue;
const setSpy = jasmine.createSpy(`set ${prop}`).and.callFake(setMockValue);
const getSpy = jasmine.createSpy(`get ${prop}`).and.callFake(() => value);
const setSpy = jasmine.createSpy(`set ${String(prop)}`).and.callFake(setMockValue);
const getSpy = jasmine.createSpy(`get ${String(prop)}`).and.callFake(() => value);

const installSpies = () => {
value = ctx[prop];
Expand Down
Loading

0 comments on commit 010f3b3

Please sign in to comment.