diff --git a/devtools/projects/ng-devtools/src/lib/devtools-tabs/diffing/index.ts b/devtools/projects/ng-devtools/src/lib/devtools-tabs/diffing/index.ts index 4fd3597af35..0aaaaf36644 100644 --- a/devtools/projects/ng-devtools/src/lib/devtools-tabs/diffing/index.ts +++ b/devtools/projects/ng-devtools/src/lib/devtools-tabs/diffing/index.ts @@ -43,9 +43,9 @@ export const diff = (differ: DefaultIterableDiffer, 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; diff --git a/devtools/projects/shell-browser/src/app/chrome-window-extensions.ts b/devtools/projects/shell-browser/src/app/chrome-window-extensions.ts index c959191857f..a12a093b63c 100644 --- a/devtools/projects/shell-browser/src/app/chrome-window-extensions.ts +++ b/devtools/projects/shell-browser/src/app/chrome-window-extensions.ts @@ -14,7 +14,7 @@ export const initializeExtendedWindowOperations = () => { extendWindowOperations(window, {inspectedApplication: chromeWindowExtensions}); }; -const extendWindowOperations = (target, classImpl: T) => { +const extendWindowOperations = (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`); diff --git a/goldens/public-api/core/global_utils.md b/goldens/public-api/core/global_utils.md index 3423e699627..7158f70d883 100644 --- a/goldens/public-api/core/global_utils.md +++ b/goldens/public-api/core/global_utils.md @@ -27,7 +27,7 @@ export interface DirectiveDebugMetadata { export function getComponent(element: Element): T | null; // @public -export function getContext(element: Element): T | null; +export function getContext(element: Element): T | null; // @public export function getDirectiveMetadata(directiveOrComponentInstance: any): ComponentDebugMetadata | DirectiveDebugMetadata | null; @@ -59,7 +59,6 @@ export interface Listener { useCapture: boolean; } - // (No @packageDocumentation comment for this package) ``` diff --git a/integration/bazel_workspace_tests/bazel_ngtsc_plugin/package.json b/integration/bazel_workspace_tests/bazel_ngtsc_plugin/package.json index 8fedb1293cd..76f16c02fb8 100644 --- a/integration/bazel_workspace_tests/bazel_ngtsc_plugin/package.json +++ b/integration/bazel_workspace_tests/bazel_ngtsc_plugin/package.json @@ -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", diff --git a/integration/bazel_workspace_tests/bazel_ngtsc_plugin/yarn.lock b/integration/bazel_workspace_tests/bazel_ngtsc_plugin/yarn.lock index 382a89fd656..8669889ad55 100644 --- a/integration/bazel_workspace_tests/bazel_ngtsc_plugin/yarn.lock +++ b/integration/bazel_workspace_tests/bazel_ngtsc_plugin/yarn.lock @@ -265,10 +265,10 @@ "@bazel/bazelisk@file:../../../node_modules/@bazel/bazelisk": version "1.11.0" -"@bazel/concatjs@5.4.0": - version "5.4.0" - resolved "https://registry.yarnpkg.com/@bazel/concatjs/-/concatjs-5.4.0.tgz#04e752a6ea3e684f00879e6683657c4ede72df6e" - integrity sha512-jlupaDKxqFS3B1lttOIgkKxirP7v5Qx7KCFtOXO7JxtvYJD/qKtKXEQggTrGKJqLPyiZlNiYimHHGICLSWIZcQ== +"@bazel/concatjs@5.4.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" diff --git a/integration/nodenext_resolution/BUILD.bazel b/integration/nodenext_resolution/BUILD.bazel new file mode 100644 index 00000000000..33afcf1a1b0 --- /dev/null +++ b/integration/nodenext_resolution/BUILD.bazel @@ -0,0 +1,5 @@ +load("//integration:index.bzl", "ng_integration_test") + +ng_integration_test( + name = "test", +) diff --git a/integration/nodenext_resolution/include-all.ts b/integration/nodenext_resolution/include-all.ts new file mode 100644 index 00000000000..8337fd40e77 --- /dev/null +++ b/integration/nodenext_resolution/include-all.ts @@ -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, +}; diff --git a/integration/nodenext_resolution/package.json b/integration/nodenext_resolution/package.json new file mode 100644 index 00000000000..6f1647ac3e2 --- /dev/null +++ b/integration/nodenext_resolution/package.json @@ -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" + } +} diff --git a/integration/nodenext_resolution/tsconfig.json b/integration/nodenext_resolution/tsconfig.json new file mode 100644 index 00000000000..d792e3274e6 --- /dev/null +++ b/integration/nodenext_resolution/tsconfig.json @@ -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" + ] +} diff --git a/integration/typings_test_ts47/BUILD.bazel b/integration/typings_test_ts47/BUILD.bazel new file mode 100644 index 00000000000..dca784fda7b --- /dev/null +++ b/integration/typings_test_ts47/BUILD.bazel @@ -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"], +) diff --git a/integration/typings_test_ts47/include-all.ts b/integration/typings_test_ts47/include-all.ts new file mode 100644 index 00000000000..925e0ef0785 --- /dev/null +++ b/integration/typings_test_ts47/include-all.ts @@ -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, +}; diff --git a/integration/typings_test_ts47/package.json b/integration/typings_test_ts47/package.json new file mode 100644 index 00000000000..871a11f022c --- /dev/null +++ b/integration/typings_test_ts47/package.json @@ -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" + } +} diff --git a/integration/typings_test_ts47/tsconfig.json b/integration/typings_test_ts47/tsconfig.json new file mode 100644 index 00000000000..30e25c22097 --- /dev/null +++ b/integration/typings_test_ts47/tsconfig.json @@ -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" + ] +} diff --git a/package.json b/package.json index 2988cf29950..b4049fff5ad 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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" diff --git a/packages/bazel/package.json b/packages/bazel/package.json index 912b85684a5..d83c99c612c 100644 --- a/packages/bazel/package.json +++ b/packages/bazel/package.json @@ -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": { diff --git a/packages/compiler-cli/ngcc/test/helpers/spy_utils.ts b/packages/compiler-cli/ngcc/test/helpers/spy_utils.ts index 881cf9fa932..95de698ecec 100644 --- a/packages/compiler-cli/ngcc/test/helpers/spy_utils.ts +++ b/packages/compiler-cli/ngcc/test/helpers/spy_utils.ts @@ -93,8 +93,8 @@ export const spyProperty = (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]; diff --git a/packages/compiler-cli/ngcc/test/packages/configuration_spec.ts b/packages/compiler-cli/ngcc/test/packages/configuration_spec.ts index cf63df31674..5c35964643d 100644 --- a/packages/compiler-cli/ngcc/test/packages/configuration_spec.ts +++ b/packages/compiler-cli/ngcc/test/packages/configuration_spec.ts @@ -697,7 +697,7 @@ runInEachFileSystem(() => { }); it('should correctly handle pre-release versions and version ranges', () => { - Object.assign(DEFAULT_NGCC_CONFIG.packages, { + Object.assign(DEFAULT_NGCC_CONFIG.packages!, { 'package-1': { entryPoints: { './entry-point-1': {}, diff --git a/packages/compiler-cli/package.json b/packages/compiler-cli/package.json index 8e5fc22014a..7c9f335e3ce 100644 --- a/packages/compiler-cli/package.json +++ b/packages/compiler-cli/package.json @@ -66,7 +66,7 @@ }, "peerDependencies": { "@angular/compiler": "0.0.0-PLACEHOLDER", - "typescript": ">=4.6.2 <4.7" + "typescript": ">=4.6.2 <4.8" }, "repository": { "type": "git", diff --git a/packages/compiler-cli/src/ngtsc/typecheck/src/ts_util.ts b/packages/compiler-cli/src/ngtsc/typecheck/src/ts_util.ts index d5bc3f87792..e64a38845e6 100644 --- a/packages/compiler-cli/src/ngtsc/typecheck/src/ts_util.ts +++ b/packages/compiler-cli/src/ngtsc/typecheck/src/ts_util.ts @@ -10,6 +10,8 @@ import ts from 'typescript'; import {ClassDeclaration} from '../../reflection'; +const PARSED_TS_VERSION = parseFloat(ts.versionMajorMinor); + /** * A `Set` of `ts.SyntaxKind`s of `ts.Expression` which are safe to wrap in a `ts.AsExpression` @@ -134,6 +136,21 @@ export function tsCallMethod( /* argumentsArray */ args); } +/** + * Updates a `ts.TypeParameter` declaration. + * + * TODO(crisbeto): this is a backwards-compatibility layer for versions of TypeScript less than 4.7. + * We should remove it once we have dropped support for the older versions. + */ +export function tsUpdateTypeParameterDeclaration( + node: ts.TypeParameterDeclaration, name: ts.Identifier, constraint: ts.TypeNode|undefined, + defaultType: ts.TypeNode|undefined): ts.TypeParameterDeclaration { + return PARSED_TS_VERSION < 4.7 ? + ts.factory.updateTypeParameterDeclaration(node, name, constraint, defaultType) : + (ts.factory.updateTypeParameterDeclaration as any)( + node, /* modifiers */[], name, constraint, defaultType); +} + export function checkIfClassIsExported(node: ClassDeclaration): boolean { // A class is exported if one of two conditions is met: // 1) it has the 'export' modifier. diff --git a/packages/compiler-cli/src/ngtsc/typecheck/src/type_constructor.ts b/packages/compiler-cli/src/ngtsc/typecheck/src/type_constructor.ts index 2a83aa8e9d4..3ad2b0bc2af 100644 --- a/packages/compiler-cli/src/ngtsc/typecheck/src/type_constructor.ts +++ b/packages/compiler-cli/src/ngtsc/typecheck/src/type_constructor.ts @@ -12,7 +12,7 @@ import {ClassDeclaration, ReflectionHost} from '../../reflection'; import {TypeCtorMetadata} from '../api'; import {checkIfGenericTypeBoundsCanBeEmitted, ReferenceEmitEnvironment} from './tcb_util'; -import {tsCreateTypeQueryForCoercedInput} from './ts_util'; +import {tsCreateTypeQueryForCoercedInput, tsUpdateTypeParameterDeclaration} from './ts_util'; export function generateTypeCtorDeclarationFn( node: ClassDeclaration, meta: TypeCtorMetadata, nodeTypeRef: ts.EntityName, @@ -244,11 +244,9 @@ function typeParametersWithDefaultTypes(params: ReadonlyArray { if (param.default === undefined) { - return ts.factory.updateTypeParameterDeclaration( - /* node */ param, - /* name */ param.name, - /* constraint */ param.constraint, - /* defaultType */ ts.factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword)); + return tsUpdateTypeParameterDeclaration( + param, param.name, param.constraint, + ts.factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword)); } else { return param; } diff --git a/packages/compiler-cli/src/ngtsc/typecheck/src/type_parameter_emitter.ts b/packages/compiler-cli/src/ngtsc/typecheck/src/type_parameter_emitter.ts index 36ed6008c60..291b3088bc0 100644 --- a/packages/compiler-cli/src/ngtsc/typecheck/src/type_parameter_emitter.ts +++ b/packages/compiler-cli/src/ngtsc/typecheck/src/type_parameter_emitter.ts @@ -10,6 +10,7 @@ import ts from 'typescript'; import {OwningModule, Reference} from '../../imports'; import {DeclarationNode, ReflectionHost} from '../../reflection'; +import {tsUpdateTypeParameterDeclaration} from './ts_util'; import {canEmitType, TypeEmitter} from './type_emitter'; @@ -73,11 +74,7 @@ export class TypeParameterEmitter { const defaultType = typeParam.default !== undefined ? emitter.emitType(typeParam.default) : undefined; - return ts.factory.updateTypeParameterDeclaration( - /* node */ typeParam, - /* name */ typeParam.name, - /* constraint */ constraint, - /* defaultType */ defaultType); + return tsUpdateTypeParameterDeclaration(typeParam, typeParam.name, constraint, defaultType); }); } diff --git a/packages/compiler-cli/src/ngtsc/typecheck/test/type_check_block_spec.ts b/packages/compiler-cli/src/ngtsc/typecheck/test/type_check_block_spec.ts index 4c1f854ad30..7747242f115 100644 --- a/packages/compiler-cli/src/ngtsc/typecheck/test/type_check_block_spec.ts +++ b/packages/compiler-cli/src/ngtsc/typecheck/test/type_check_block_spec.ts @@ -480,7 +480,7 @@ describe('type check blocks', () => { expect(tcb(TEMPLATE, DIRECTIVES)) .toContain( 'var _t1: i0.Dir = null!; ' + - 'var _t2: typeof _t1["fieldA"] = null!; ' + + 'var _t2: (typeof _t1)["fieldA"] = null!; ' + '_t2 = (((ctx).foo)); '); }); diff --git a/packages/compiler-cli/src/typescript_support.ts b/packages/compiler-cli/src/typescript_support.ts index ccc93f19542..26bec66c9e1 100644 --- a/packages/compiler-cli/src/typescript_support.ts +++ b/packages/compiler-cli/src/typescript_support.ts @@ -26,7 +26,7 @@ const MIN_TS_VERSION = '4.6.2'; * Note: this check is disabled in g3, search for * `angularCompilerOptions.disableTypeScriptVersionCheck` config param value in g3. */ -const MAX_TS_VERSION = '4.7.0'; +const MAX_TS_VERSION = '4.8.0'; /** * The currently used version of TypeScript, which can be adjusted for testing purposes using diff --git a/packages/compiler-cli/test/perform_watch_spec.ts b/packages/compiler-cli/test/perform_watch_spec.ts index 62270e5676b..7a17ca6e4fa 100644 --- a/packages/compiler-cli/test/perform_watch_spec.ts +++ b/packages/compiler-cli/test/perform_watch_spec.ts @@ -105,8 +105,12 @@ describe('perform watch', () => { expect(fs.existsSync(genPath)).toBe(true); expect(fileExistsSpy!).toHaveBeenCalledWith(mainTsPath); expect(fileExistsSpy!).toHaveBeenCalledWith(utilTsPath); - expect(getSourceFileSpy!).toHaveBeenCalledWith(mainTsPath, ts.ScriptTarget.ES5); - expect(getSourceFileSpy!).toHaveBeenCalledWith(utilTsPath, ts.ScriptTarget.ES5); + expect(getSourceFileSpy!).toHaveBeenCalledWith(mainTsPath, jasmine.objectContaining({ + languageVersion: ts.ScriptTarget.ES5 + })); + expect(getSourceFileSpy!).toHaveBeenCalledWith(utilTsPath, jasmine.objectContaining({ + languageVersion: ts.ScriptTarget.ES5 + })); fileExistsSpy!.calls.reset(); getSourceFileSpy!.calls.reset(); diff --git a/packages/core/src/render3/component_ref.ts b/packages/core/src/render3/component_ref.ts index a7923c3d9ef..db3b7260814 100644 --- a/packages/core/src/render3/component_ref.ts +++ b/packages/core/src/render3/component_ref.ts @@ -78,16 +78,17 @@ class ChainedInjector implements Injector { constructor(private injector: Injector, private parentInjector: Injector) {} get(token: ProviderToken, notFoundValue?: T, flags?: InjectFlags): T { - const value = this.injector.get(token, NOT_FOUND_CHECK_ONLY_ELEMENT_INJECTOR as T, flags); + const value = this.injector.get( + token, NOT_FOUND_CHECK_ONLY_ELEMENT_INJECTOR, flags); if (value !== NOT_FOUND_CHECK_ONLY_ELEMENT_INJECTOR || - notFoundValue === NOT_FOUND_CHECK_ONLY_ELEMENT_INJECTOR) { + notFoundValue === (NOT_FOUND_CHECK_ONLY_ELEMENT_INJECTOR as unknown as T)) { // Return the value from the root element injector when // - it provides it // (value !== NOT_FOUND_CHECK_ONLY_ELEMENT_INJECTOR) // - the module injector should not be checked // (notFoundValue === NOT_FOUND_CHECK_ONLY_ELEMENT_INJECTOR) - return value; + return value as T; } return this.parentInjector.get(token, notFoundValue, flags); diff --git a/packages/core/src/render3/context_discovery.ts b/packages/core/src/render3/context_discovery.ts index 4753d095d54..9dc6df4d276 100644 --- a/packages/core/src/render3/context_discovery.ts +++ b/packages/core/src/render3/context_discovery.ts @@ -196,10 +196,10 @@ export function readPatchedData(target: any): LView|LContext|null { return (typeof data === 'number') ? getLViewById(data) : data || null; } -export function readPatchedLView(target: any): LView|null { +export function readPatchedLView(target: any): LView|null { const value = readPatchedData(target); if (value) { - return isLView(value) ? value : value.lView; + return (isLView(value) ? value : value.lView) as LView; } return null; } diff --git a/packages/core/src/render3/di.ts b/packages/core/src/render3/di.ts index 1fee25dc9d6..b4b34a8e7a6 100644 --- a/packages/core/src/render3/di.ts +++ b/packages/core/src/render3/di.ts @@ -489,7 +489,7 @@ function lookupTokenUsingNodeInjector( // At this point, we have an injector which *may* contain the token, so we step through // the providers and directives associated with the injector's corresponding node to get // the instance. - const instance: T|null = searchTokensOnInjector( + const instance: T|{}|null = searchTokensOnInjector( injectorIndex, lView, token, previousTView, flags, hostTElementNode); if (instance !== NOT_FOUND) { return instance; @@ -803,7 +803,8 @@ function lookupTokenUsingEmbeddedInjector( // Before we go to the next LView, check if the token exists on the current embedded injector. const embeddedViewInjector = currentLView[EMBEDDED_VIEW_INJECTOR]; if (embeddedViewInjector) { - const embeddedViewInjectorValue = embeddedViewInjector.get(token, NOT_FOUND as T, flags); + const embeddedViewInjectorValue = + embeddedViewInjector.get(token, NOT_FOUND as T | {}, flags); if (embeddedViewInjectorValue !== NOT_FOUND) { return embeddedViewInjectorValue; } diff --git a/packages/core/src/render3/instructions/change_detection.ts b/packages/core/src/render3/instructions/change_detection.ts index fb519ec4704..d03e0df3227 100644 --- a/packages/core/src/render3/instructions/change_detection.ts +++ b/packages/core/src/render3/instructions/change_detection.ts @@ -10,6 +10,7 @@ import {assertDefined} from '../../util/assert'; import {getComponentViewByInstance} from '../context_discovery'; import {CONTEXT, RootContext, RootContextFlags, TVIEW} from '../interfaces/view'; import {getRootView} from '../util/view_traversal_utils'; + import {detectChangesInternal, markViewDirty, scheduleTick, tickRootContext} from './shared'; /** @@ -53,7 +54,7 @@ export function markDirty(component: {}): void { * single change detection run. By default, the scheduler is `requestAnimationFrame`, but can * be changed when calling `renderComponent` and providing the `scheduler` option. */ -export function tick(component: T): void { +export function tick(component: {}): void { const rootView = getRootView(component); const rootContext = rootView[CONTEXT] as RootContext; tickRootContext(rootContext); diff --git a/packages/core/src/render3/instructions/listener.ts b/packages/core/src/render3/instructions/listener.ts index ae31a5ffe8b..581875cd078 100644 --- a/packages/core/src/render3/instructions/listener.ts +++ b/packages/core/src/render3/instructions/listener.ts @@ -40,7 +40,7 @@ import {getOrCreateLViewCleanup, getOrCreateTViewCleanup, handleError, loadCompo export function ɵɵlistener( eventName: string, listenerFn: (e?: any) => any, useCapture?: boolean, eventTargetResolver?: GlobalTargetResolver): typeof ɵɵlistener { - const lView = getLView(); + const lView = getLView<{}|null>(); const tView = getTView(); const tNode = getCurrentTNode()!; listenerInternal( @@ -73,7 +73,7 @@ export function ɵɵlistener( export function ɵɵsyntheticHostListener( eventName: string, listenerFn: (e?: any) => any): typeof ɵɵsyntheticHostListener { const tNode = getCurrentTNode()!; - const lView = getLView(); + const lView = getLView<{}|null>(); const tView = getTView(); const currentDef = getCurrentDirectiveDef(tView.data); const renderer = loadComponentRenderer(currentDef, tNode, lView); @@ -114,7 +114,7 @@ function findExistingListener( } function listenerInternal( - tView: TView, lView: LView, renderer: Renderer3, tNode: TNode, eventName: string, + tView: TView, lView: LView<{}|null>, renderer: Renderer3, tNode: TNode, eventName: string, listenerFn: (e?: any) => any, useCapture: boolean, eventTargetResolver?: GlobalTargetResolver): void { const isTNodeDirectiveHost = isDirectiveHost(tNode); @@ -250,7 +250,7 @@ function executeListenerWithErrorHandling( * (the procedural renderer does this already, so in those cases, we should skip) */ function wrapListener( - tNode: TNode, lView: LView, context: {}|null, listenerFn: (e?: any) => any, + tNode: TNode, lView: LView<{}|null>, context: {}|null, listenerFn: (e?: any) => any, wrapWithPreventDefault: boolean): EventListener { // Note: we are performing most of the work in the listener function itself // to optimize listener registration. diff --git a/packages/core/src/render3/instructions/lview_debug.ts b/packages/core/src/render3/instructions/lview_debug.ts index e9c5f4652a2..48d65325ab0 100644 --- a/packages/core/src/render3/instructions/lview_debug.ts +++ b/packages/core/src/render3/instructions/lview_debug.ts @@ -73,7 +73,7 @@ interface TViewDebug extends ITView { * * Simple slice will keep the same type, and we need it to be LView */ -export function cloneToLViewFromTViewBlueprint(tView: TView): LView { +export function cloneToLViewFromTViewBlueprint(tView: TView): LView { const debugTView = tView as TViewDebug; const lView = getLViewToClone(debugTView.type, tView.template && tView.template.name); return lView.concat(tView.blueprint) as any; @@ -387,9 +387,9 @@ export function attachLContainerDebug(lContainer: LContainer) { attachDebugObject(lContainer, new LContainerDebug(lContainer)); } -export function toDebug(obj: LView): ILViewDebug; -export function toDebug(obj: LView|null): ILViewDebug|null; -export function toDebug(obj: LView|LContainer|null): ILViewDebug|ILContainerDebug|null; +export function toDebug(obj: LView): ILViewDebug; +export function toDebug(obj: LView|null): ILViewDebug|null; +export function toDebug(obj: LView|LContainer|null): ILViewDebug|ILContainerDebug|null; export function toDebug(obj: any): any { if (obj) { const debug = (obj as any).debug; @@ -432,8 +432,8 @@ function toHtml(value: any, includeChildren: boolean = false): string|null { return null; } -export class LViewDebug implements ILViewDebug { - constructor(private readonly _raw_lView: LView) {} +export class LViewDebug implements ILViewDebug { + constructor(private readonly _raw_lView: LView) {} /** * Flags associated with the `LView` unpacked into a more readable state. @@ -453,8 +453,8 @@ export class LViewDebug implements ILViewDebug { indexWithinInitPhase: flags >> LViewFlags.IndexWithinInitPhaseShift, }; } - get parent(): ILViewDebug|ILContainerDebug|null { - return toDebug(this._raw_lView[PARENT]); + get parent(): ILViewDebug|ILContainerDebug|null { + return toDebug(this._raw_lView[PARENT] as LView| LContainer | null); } get hostHTML(): string|null { return toHtml(this._raw_lView[HOST], true); @@ -462,7 +462,7 @@ export class LViewDebug implements ILViewDebug { get html(): string { return (this.nodes || []).map(mapToHTML).join(''); } - get context(): {}|null { + get context(): T { return this._raw_lView[CONTEXT]; } /** @@ -498,8 +498,8 @@ export class LViewDebug implements ILViewDebug { get childHead(): ILViewDebug|ILContainerDebug|null { return toDebug(this._raw_lView[CHILD_HEAD]); } - get next(): ILViewDebug|ILContainerDebug|null { - return toDebug(this._raw_lView[NEXT]); + get next(): ILViewDebug|ILContainerDebug|null { + return toDebug(this._raw_lView[NEXT] as LView| LContainer | null); } get childTail(): ILViewDebug|ILContainerDebug|null { return toDebug(this._raw_lView[CHILD_TAIL]); @@ -534,11 +534,11 @@ export class LViewDebug implements ILViewDebug { /** * Normalized view of child views (and containers) attached at this location. */ - get childViews(): Array { - const childViews: Array = []; + get childViews(): Array|ILContainerDebug> { + const childViews: Array|ILContainerDebug> = []; let child = this.childHead; while (child) { - childViews.push(child); + childViews.push(child as ILViewDebug| ILContainerDebug); child = child.next; } return childViews; diff --git a/packages/core/src/render3/instructions/shared.ts b/packages/core/src/render3/instructions/shared.ts index 5c33cd1bcb3..1eaf733fe61 100644 --- a/packages/core/src/render3/instructions/shared.ts +++ b/packages/core/src/render3/instructions/shared.ts @@ -292,20 +292,20 @@ export function allocExpando( * - updating static queries (if any); * - creating child components defined in a given view. */ -export function renderView(tView: TView, lView: LView, context: T): void { +export function renderView(tView: TView, lView: LView, context: T): void { ngDevMode && assertEqual(isCreationMode(lView), true, 'Should be run in creation mode'); enterView(lView); try { const viewQuery = tView.viewQuery; if (viewQuery !== null) { - executeViewQueryFn(RenderFlags.Create, viewQuery, context); + executeViewQueryFn(RenderFlags.Create, viewQuery, context); } // Execute a template associated with this view, if it exists. A template function might not be // defined for the root component views. const templateFn = tView.template; if (templateFn !== null) { - executeTemplate(tView, lView, templateFn, RenderFlags.Create, context); + executeTemplate(tView, lView, templateFn, RenderFlags.Create, context); } // This needs to be set before children are processed to support recursive components. @@ -328,7 +328,7 @@ export function renderView(tView: TView, lView: LView, context: T): void { // in case a child component has projected a container. The LContainer needs // to exist so the embedded views are properly attached by the container. if (tView.staticViewQueries) { - executeViewQueryFn(RenderFlags.Update, tView.viewQuery!, context); + executeViewQueryFn(RenderFlags.Update, tView.viewQuery!, context); } // Render child component views. @@ -439,7 +439,7 @@ export function refreshView( // refresh, the template might not yet be inserted. const viewQuery = tView.viewQuery; if (viewQuery !== null) { - executeViewQueryFn(RenderFlags.Update, viewQuery, context); + executeViewQueryFn(RenderFlags.Update, viewQuery, context); } // execute view hooks (AfterViewInit, AfterViewChecked) @@ -507,7 +507,7 @@ export function renderComponentOrTemplate( } function executeTemplate( - tView: TView, lView: LView, templateFn: ComponentTemplate, rf: RenderFlags, context: T) { + tView: TView, lView: LView, templateFn: ComponentTemplate, rf: RenderFlags, context: T) { const prevSelectedIndex = getSelectedIndex(); const isUpdatePhase = rf & RenderFlags.Update; try { @@ -520,14 +520,14 @@ function executeTemplate( const preHookType = isUpdatePhase ? ProfilerEvent.TemplateUpdateStart : ProfilerEvent.TemplateCreateStart; - profiler(preHookType, context); + profiler(preHookType, context as unknown as {}); templateFn(rf, context); } finally { setSelectedIndex(prevSelectedIndex); const postHookType = isUpdatePhase ? ProfilerEvent.TemplateUpdateEnd : ProfilerEvent.TemplateCreateEnd; - profiler(postHookType, context); + profiler(postHookType, context as unknown as {}); } } @@ -1995,7 +1995,7 @@ export function checkNoChangesInRootView(lView: LView): void { } function executeViewQueryFn( - flags: RenderFlags, viewQueryFn: ViewQueriesFunction<{}>, component: T): void { + flags: RenderFlags, viewQueryFn: ViewQueriesFunction, component: T): void { ngDevMode && assertDefined(viewQueryFn, 'View queries function to execute must be defined.'); setCurrentQueryIndex(0); viewQueryFn(flags, component); diff --git a/packages/core/src/render3/interfaces/view.ts b/packages/core/src/render3/interfaces/view.ts index 93807edb45f..0fe6ae7fd2b 100644 --- a/packages/core/src/render3/interfaces/view.ts +++ b/packages/core/src/render3/interfaces/view.ts @@ -78,7 +78,7 @@ export interface OpaqueViewState { * Keeping separate state for each view facilities view insertion / deletion, so we * don't have to edit the data array based on which views are present. */ -export interface LView extends Array { +export interface LView extends Array { /** * Human readable representation of the `LView`. * @@ -180,7 +180,7 @@ export interface LView extends Array { * - For non-root components, the context is the component instance, * - For inline views, the context is null. */ - [CONTEXT]: {}|RootContext|null; + [CONTEXT]: T; /** An optional Module Injector to be used as fall back after Element Injectors are consulted. */ readonly[INJECTOR]: Injector|null; @@ -818,7 +818,7 @@ export const enum RootContextFlags { * RootContext contains information which is shared for all components which * were bootstrapped with {@link renderComponent}. */ -export interface RootContext { +export interface RootContext { /** * A function used for scheduling change detection in the future. Usually * this is `requestAnimationFrame`. @@ -836,7 +836,7 @@ export interface RootContext { * RootComponents - The components that were instantiated by the call to * {@link renderComponent}. */ - components: {}[]; + components: T[]; /** * The player flushing handler to kick off all animations @@ -935,7 +935,7 @@ export const unusedValueExportToPlacateAjd = 1; * `LViewDebug` for easier debugging and test writing. It is the intent of `LViewDebug` to be used * in tests. */ -export interface LViewDebug { +export interface LViewDebug { /** * Flags associated with the `LView` unpacked into a more readable state. * @@ -973,7 +973,7 @@ export interface LViewDebug { * * (Usually the component) */ - readonly context: {}|null; + readonly context: T; /** * Hierarchical tree of nodes. diff --git a/packages/core/src/render3/pipe.ts b/packages/core/src/render3/pipe.ts index dd253fabc4d..2a9e5f1cb9c 100644 --- a/packages/core/src/render3/pipe.ts +++ b/packages/core/src/render3/pipe.ts @@ -9,6 +9,7 @@ import {PipeTransform} from '../change_detection/pipe_transform'; import {setInjectImplementation} from '../di/inject_switch'; import {RuntimeError, RuntimeErrorCode} from '../errors'; +import {Type} from '../interface/type'; import {getFactoryDef} from './definition_factory'; import {setIncludeViewProviders} from './di'; @@ -83,7 +84,7 @@ function getPipeDef(name: string, registry: PipeDefList|null): PipeDef|unde } if (ngDevMode) { const lView = getLView(); - const declarationLView = lView[DECLARATION_COMPONENT_VIEW]; + const declarationLView = lView[DECLARATION_COMPONENT_VIEW] as LView>; const context = declarationLView[CONTEXT]; const component = context ? ` in the '${context.constructor.name}' component` : ''; throw new RuntimeError( diff --git a/packages/core/src/render3/state.ts b/packages/core/src/render3/state.ts index 24e6d8cec3b..a947ef5b83e 100644 --- a/packages/core/src/render3/state.ts +++ b/packages/core/src/render3/state.ts @@ -266,8 +266,8 @@ export function ɵɵdisableBindings(): void { /** * Return the current `LView`. */ -export function getLView(): LView { - return instructionState.lFrame.lView; +export function getLView(): LView { + return instructionState.lFrame.lView as LView; } /** @@ -294,7 +294,7 @@ export function getTView(): TView { */ export function ɵɵrestoreView(viewToRestore: OpaqueViewState): T { instructionState.lFrame.contextLView = viewToRestore as any as LView; - return (viewToRestore as any as LView)[CONTEXT] as T; + return (viewToRestore as any as LView)[CONTEXT] as unknown as T; } @@ -658,7 +658,7 @@ export function leaveView() { export function nextContextImpl(level: number): T { const contextLView = instructionState.lFrame.contextLView = walkUpViews(level, instructionState.lFrame.contextLView!); - return contextLView[CONTEXT] as T; + return contextLView[CONTEXT] as unknown as T; } function walkUpViews(nestingLevel: number, currentView: LView): LView { diff --git a/packages/core/src/render3/util/discovery_utils.ts b/packages/core/src/render3/util/discovery_utils.ts index caaf7cec92d..12c38e150b1 100644 --- a/packages/core/src/render3/util/discovery_utils.ts +++ b/packages/core/src/render3/util/discovery_utils.ts @@ -19,7 +19,7 @@ import {LContext} from '../interfaces/context'; import {DirectiveDef} from '../interfaces/definition'; import {TElementNode, TNode, TNodeProviderIndexes} from '../interfaces/node'; import {isLView} from '../interfaces/type_checks'; -import {CLEANUP, CONTEXT, DebugNode, FLAGS, LView, LViewFlags, T_HOST, TVIEW, TViewType} from '../interfaces/view'; +import {CLEANUP, CONTEXT, DebugNode, FLAGS, LView, LViewFlags, RootContext, T_HOST, TVIEW, TViewType} from '../interfaces/view'; import {stringifyForError} from './stringify_utils'; import {getLViewParent, getRootContext} from './view_traversal_utils'; @@ -67,7 +67,7 @@ export function getComponent(element: Element): T|null { context.component = getComponentAtNodeIndex(context.nodeIndex, lView); } - return context.component as T; + return context.component as unknown as T; } @@ -83,7 +83,7 @@ export function getComponent(element: Element): T|null { * @publicApi * @globalApi ng */ -export function getContext(element: Element): T|null { +export function getContext(element: Element): T|null { assertDomElement(element); const context = getLContext(element)!; const lView = context ? context.lView : null; @@ -114,7 +114,7 @@ export function getOwningComponent(elementOrDir: Element|{}): T|null { while (lView[TVIEW].type === TViewType.Embedded && (parent = getLViewParent(lView)!)) { lView = parent; } - return lView[FLAGS] & LViewFlags.IsRoot ? null : lView[CONTEXT] as T; + return lView[FLAGS] & LViewFlags.IsRoot ? null : lView[CONTEXT] as unknown as T; } /** @@ -129,8 +129,8 @@ export function getOwningComponent(elementOrDir: Element|{}): T|null { * @globalApi ng */ export function getRootComponents(elementOrDir: Element|{}): {}[] { - const lView = readPatchedLView(elementOrDir); - return lView !== null ? [...getRootContext(lView).components] : []; + const lView = readPatchedLView<{}>(elementOrDir); + return lView !== null ? [...getRootContext(lView).components as unknown as {}[]] : []; } /** diff --git a/packages/core/src/render3/util/view_traversal_utils.ts b/packages/core/src/render3/util/view_traversal_utils.ts index b52e34de4e7..9edaceaa46d 100644 --- a/packages/core/src/render3/util/view_traversal_utils.ts +++ b/packages/core/src/render3/util/view_traversal_utils.ts @@ -31,14 +31,14 @@ export function getLViewParent(lView: LView): LView|null { * * @param componentOrLView any component or `LView` */ -export function getRootView(componentOrLView: LView|{}): LView { +export function getRootView(componentOrLView: LView|{}): LView { ngDevMode && assertDefined(componentOrLView, 'component'); let lView = isLView(componentOrLView) ? componentOrLView : readPatchedLView(componentOrLView)!; while (lView && !(lView[FLAGS] & LViewFlags.IsRoot)) { lView = getLViewParent(lView)!; } ngDevMode && assertLView(lView); - return lView; + return lView as LView; } /** @@ -48,7 +48,7 @@ export function getRootView(componentOrLView: LView|{}): LView { * * @param viewOrComponent the `LView` or component to get the root context for. */ -export function getRootContext(viewOrComponent: LView|{}): RootContext { +export function getRootContext(viewOrComponent: LView|{}): RootContext { const rootView = getRootView(viewOrComponent); ngDevMode && assertDefined(rootView[CONTEXT], 'RootView has no context. Perhaps it is disconnected?'); diff --git a/packages/core/src/render3/view_ref.ts b/packages/core/src/render3/view_ref.ts index d1f39334654..aac220d2ee8 100644 --- a/packages/core/src/render3/view_ref.ts +++ b/packages/core/src/render3/view_ref.ts @@ -60,11 +60,11 @@ export class ViewRef implements viewEngine_EmbeddedViewRef, viewEngine_Int private _cdRefInjectingView?: LView) {} get context(): T { - return this._lView[CONTEXT] as T; + return this._lView[CONTEXT] as unknown as T; } set context(value: T) { - this._lView[CONTEXT] = value; + this._lView[CONTEXT] = value as unknown as {}; } get destroyed(): boolean { @@ -271,7 +271,7 @@ export class ViewRef implements viewEngine_EmbeddedViewRef, viewEngine_Int * See {@link ChangeDetectorRef#detach detach} for more information. */ detectChanges(): void { - detectChangesInternal(this._lView[TVIEW], this._lView, this.context); + detectChangesInternal(this._lView[TVIEW], this._lView, this.context as unknown as {}); } /** @@ -281,7 +281,7 @@ export class ViewRef implements viewEngine_EmbeddedViewRef, viewEngine_Int * introduce other changes. */ checkNoChanges(): void { - checkNoChangesInternal(this._lView[TVIEW], this._lView, this.context); + checkNoChangesInternal(this._lView[TVIEW], this._lView, this.context as unknown as {}); } attachToViewContainerRef() { diff --git a/packages/core/src/util/raf.ts b/packages/core/src/util/raf.ts index 284049ac38c..1fc562f0300 100644 --- a/packages/core/src/util/raf.ts +++ b/packages/core/src/util/raf.ts @@ -11,7 +11,7 @@ export function getNativeRequestAnimationFrame() { let nativeRequestAnimationFrame: (callback: FrameRequestCallback) => number = global['requestAnimationFrame']; let nativeCancelAnimationFrame: (handle: number) => void = global['cancelAnimationFrame']; - if (typeof Zone !== 'undefined' && nativeRequestAnimationFrame && nativeCancelAnimationFrame) { + if (typeof Zone !== 'undefined' && nativeRequestAnimationFrame! && nativeCancelAnimationFrame!) { // use unpatched version of requestAnimationFrame(native delegate) if possible // to avoid another Change detection const unpatchedRequestAnimationFrame = diff --git a/packages/core/test/render3/render_util.ts b/packages/core/test/render3/render_util.ts index 0d127e573c2..d41780715fb 100644 --- a/packages/core/test/render3/render_util.ts +++ b/packages/core/test/render3/render_util.ts @@ -179,11 +179,11 @@ export class TemplateFixture extends BaseFixture { /** * Fixture for testing Components in a convenient way. */ -export class ComponentFixture extends BaseFixture { +export class ComponentFixture extends BaseFixture { component: T; requestAnimationFrame: {(fn: () => void): void; flush(): void; queue: (() => void)[];}; - constructor(private componentType: ComponentType, opts: { + constructor(componentType: ComponentType, opts: { injector?: Injector, sanitizer?: Sanitizer, rendererFactory?: RendererFactory3, diff --git a/packages/core/testing/src/r3_test_bed.ts b/packages/core/testing/src/r3_test_bed.ts index 0a1a6aaa36b..36f6c4b2554 100644 --- a/packages/core/testing/src/r3_test_bed.ts +++ b/packages/core/testing/src/r3_test_bed.ts @@ -322,7 +322,7 @@ export class TestBedRender3 implements TestBed { if (token as unknown === TestBedRender3) { return this as any; } - const UNDEFINED = {}; + const UNDEFINED = {} as unknown as T; const result = this.testModuleRef.injector.get(token, UNDEFINED, flags); return result === UNDEFINED ? this.compiler.injector.get(token, notFoundValue, flags) as any : result; diff --git a/packages/core/testing/src/resolvers.ts b/packages/core/testing/src/resolvers.ts index 053e58ee811..b0861e90c99 100644 --- a/packages/core/testing/src/resolvers.ts +++ b/packages/core/testing/src/resolvers.ts @@ -57,7 +57,7 @@ abstract class OverrideResolver implements Resolver { const isKnownType = annotation instanceof Directive || annotation instanceof Component || annotation instanceof Pipe || annotation instanceof NgModule; if (isKnownType) { - return annotation instanceof this.type ? annotation as T : null; + return annotation instanceof this.type ? annotation as unknown as T : null; } } return null; diff --git a/packages/language-service/test/references_and_rename_spec.ts b/packages/language-service/test/references_and_rename_spec.ts index c66ccb1044a..1f66468f874 100644 --- a/packages/language-service/test/references_and_rename_spec.ts +++ b/packages/language-service/test/references_and_rename_spec.ts @@ -377,10 +377,6 @@ describe('find references and rename locations', () => { expect(refs.length).toBe(2); assertTextSpans(refs, ['myInput']); - - // Get the declaration by finding the reference that appears first in the template - refs.sort((a, b) => a.textSpan.start - b.textSpan.start); - expect(refs[0].isDefinition).toBe(true); }); it('finds rename location in template', () => { @@ -418,10 +414,6 @@ describe('find references and rename locations', () => { expect(refs.length).toBe(2); assertTextSpans(refs, ['myTemplate']); assertFileNames(refs, ['app.html']); - - // Get the declaration by finding the reference that appears first in the template - refs.sort((a, b) => a.textSpan.start - b.textSpan.start); - expect(refs[0].isDefinition).toBe(true); }); it('finds rename location in template', () => { @@ -599,10 +591,6 @@ describe('find references and rename locations', () => { expect(refs.length).toBe(3); assertFileNames(refs, ['template.ng.html']); assertTextSpans(refs, ['hero']); - - // Get the declaration by finding the reference that appears first in the template - refs.sort((a, b) => a.textSpan.start - b.textSpan.start); - expect(refs[0].isDefinition).toBe(true); }); it('should find rename locations', () => { @@ -637,10 +625,6 @@ describe('find references and rename locations', () => { expect(refs.length).toBe(2); assertFileNames(refs, ['app.ts']); assertTextSpans(refs, ['iRef']); - - // Get the declaration by finding the reference that appears first in the template - refs.sort((a, b) => a.textSpan.start - b.textSpan.start); - expect(refs[0].isDefinition).toBe(true); }); it('should find rename locations', () => { diff --git a/packages/language-service/testing/src/project.ts b/packages/language-service/testing/src/project.ts index c4641ce95b5..2095e23fc39 100644 --- a/packages/language-service/testing/src/project.ts +++ b/packages/language-service/testing/src/project.ts @@ -102,7 +102,10 @@ export class Project { if (!this.buffers.has(projectFileName)) { const fileName = absoluteFrom(`/${this.name}/${projectFileName}`); let scriptInfo = this.tsProject.getScriptInfo(fileName); - this.projectService.openClientFile(fileName); + this.projectService.openClientFile( + // By attempting to open the file, the compiler is going to try to parse it as + // TS which will throw an error. We pass in JSX which is more permissive. + fileName, undefined, fileName.endsWith('.html') ? ts.ScriptKind.JSX : ts.ScriptKind.TS); // Mark the project as dirty because the act of opening a file may result in the version // changing since TypeScript will `switchToScriptVersionCache` when a file is opened. // Note that this emulates what we have to do in the server/extension as well. diff --git a/packages/platform-browser/src/browser/transfer_state.ts b/packages/platform-browser/src/browser/transfer_state.ts index 65ed1fb870b..93352ecfdcf 100644 --- a/packages/platform-browser/src/browser/transfer_state.ts +++ b/packages/platform-browser/src/browser/transfer_state.ts @@ -83,8 +83,8 @@ export function makeStateKey(key: string): StateKey { */ @Injectable() export class TransferState { - private store: {[k: string]: {}|undefined} = {}; - private onSerializeCallbacks: {[k: string]: () => {} | undefined} = {}; + private store: {[k: string]: unknown|undefined} = {}; + private onSerializeCallbacks: {[k: string]: () => unknown | undefined} = {}; /** @internal */ static init(initState: {}) { diff --git a/packages/zone.js/package.json b/packages/zone.js/package.json index 21177f80a4f..b3d340d612d 100644 --- a/packages/zone.js/package.json +++ b/packages/zone.js/package.json @@ -19,7 +19,7 @@ "mocha": "^9.0.0", "mock-require": "3.0.3", "promises-aplus-tests": "^2.1.2", - "typescript": "~4.6.2" + "typescript": "4.7.0-beta" }, "scripts": { "closuretest": "./scripts/closure/closure_compiler.sh", diff --git a/packages/zone.js/test/typings/package.json b/packages/zone.js/test/typings/package.json index d2164e828ec..cf168f9e786 100644 --- a/packages/zone.js/test/typings/package.json +++ b/packages/zone.js/test/typings/package.json @@ -14,6 +14,6 @@ "zone.js": "file:../../../../dist/bin/packages/zone.js/npm_package" }, "devDependencies": { - "typescript": "~4.6.2" + "typescript": "4.7.0-beta" } } diff --git a/packages/zone.js/yarn.lock b/packages/zone.js/yarn.lock index 2ac826afd17..ec91b4cfb09 100644 --- a/packages/zone.js/yarn.lock +++ b/packages/zone.js/yarn.lock @@ -4007,10 +4007,10 @@ typedarray-to-buffer@^3.1.5: dependencies: is-typedarray "^1.0.0" -typescript@~4.6.2: - version "4.6.3" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.6.3.tgz#eefeafa6afdd31d725584c67a0eaba80f6fc6c6c" - integrity sha512-yNIatDa5iaofVozS/uQJEl3JRWLKKGJKh6Yaiv0GLGSuhpFJe7P3SbHZ8/yjAHRQwKRoA6YZqlfjXWmVzoVSMw== +typescript@4.7.0-beta: + version "4.7.0-beta" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.7.0-beta.tgz#15952f24d4177479ca3d19f09436ad8c69a30563" + integrity sha512-m+CNL8lzHyHDxYYDTI+pm5hw5/bufYVGan2bokPyJY/y9C/4W/PCWMtYZ0vV9fLXbEL57elMeoaz9Evxs8UQ+A== unbox-primitive@^1.0.1: version "1.0.2" diff --git a/yarn.lock b/yarn.lock index 9c97ac4175e..ef2d09e9355 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1385,15 +1385,6 @@ resolved "https://registry.yarnpkg.com/@bazel/buildifier/-/buildifier-5.1.0.tgz#ae0b93c5d14b2b080d5a492a8bfee231101b5385" integrity sha512-gO0+//hkH+iE3AQ02mYttJAcWiE+rapP8IxmstDhwSqs+CmZJJI8Q1vAaIvMyJUT3NIf7lGljRNpzclkCPk89w== -"@bazel/concatjs@5.4.0": - version "5.4.0" - resolved "https://registry.yarnpkg.com/@bazel/concatjs/-/concatjs-5.4.0.tgz#04e752a6ea3e684f00879e6683657c4ede72df6e" - integrity sha512-jlupaDKxqFS3B1lttOIgkKxirP7v5Qx7KCFtOXO7JxtvYJD/qKtKXEQggTrGKJqLPyiZlNiYimHHGICLSWIZcQ== - dependencies: - protobufjs "6.8.8" - source-map-support "0.5.9" - tsutils "3.21.0" - "@bazel/concatjs@5.4.1": version "5.4.1" resolved "https://registry.yarnpkg.com/@bazel/concatjs/-/concatjs-5.4.1.tgz#590b7944d89136863ba4e3e264c555b0efc815de" @@ -1403,11 +1394,6 @@ source-map-support "0.5.9" tsutils "3.21.0" -"@bazel/esbuild@5.4.0": - version "5.4.0" - resolved "https://registry.yarnpkg.com/@bazel/esbuild/-/esbuild-5.4.0.tgz#94b68f71726c96f60937e0c2bb71ab04c6a0b868" - integrity sha512-jX5aPvlXqi1pqNOogJRYUiUCCqC+378QZestcW3MG/vHyMavVTCC4xvas94nnhtzc7UvufOWhYz/S1m8Orca8g== - "@bazel/esbuild@5.4.1": version "5.4.1" resolved "https://registry.yarnpkg.com/@bazel/esbuild/-/esbuild-5.4.1.tgz#e2d1e66d2cf2e5d64d35dccce21a210b1082a7c4" @@ -1418,46 +1404,31 @@ resolved "https://registry.yarnpkg.com/@bazel/ibazel/-/ibazel-0.16.2.tgz#05dd7f06659759fda30f87b15534f1e42f1201bb" integrity sha512-KgqAWMH0emL6f3xH6nqyTryoBMqlJ627LBIe9PT1PRRQPz2FtHib3FIHJPukp1slzF3hJYZvdiVwgPnHbaSOOA== -"@bazel/jasmine@5.4.0": - version "5.4.0" - resolved "https://registry.yarnpkg.com/@bazel/jasmine/-/jasmine-5.4.0.tgz#186f837951b678c39274dd9321779a40012a6bc5" - integrity sha512-hUMbuSKr6U9VXRHXfv0KIWVBue5fFskPAVbDK4dWUVuac8V2vVNQadtppOHPFOzzqZdDsUuSyXCDjqGUZYVm+Q== +"@bazel/jasmine@5.4.1": + version "5.4.1" + resolved "https://registry.yarnpkg.com/@bazel/jasmine/-/jasmine-5.4.1.tgz#f37ff9f7a742b4d73ff5e18460ae4a023e1ecfce" + integrity sha512-Exo73WlDOQMqG8BZ9QAk5OsCmTfQssqYckjofiZs8FP9ERl4vOpuBrMNYSWVSHlRtZA8+UkFmxuz5LlMRWG3og== dependencies: c8 "~7.5.0" jasmine-reporters "~2.5.0" -"@bazel/protractor@5.4.0": - version "5.4.0" - resolved "https://registry.yarnpkg.com/@bazel/protractor/-/protractor-5.4.0.tgz#9df709d0ec389bf8ea33119cf4c127279d956a1d" - integrity sha512-nCSEnyLNzAW/H400joxpnWkBOOqGBQcwYYzVWHdVKF6eigPjOYTVqEajYVI8iLMSJK1i7vx8HxCOoiiUbrW3wA== - "@bazel/protractor@5.4.1": version "5.4.1" resolved "https://registry.yarnpkg.com/@bazel/protractor/-/protractor-5.4.1.tgz#f246f5e1fbcc5ed36e6d48824009bb29482e1660" integrity sha512-uYIrYuxyZMplpov7pkjNF2igQA3CrnHOF4W68xJlHWhw3tjbacWHd4OJJ1BYrpPoYShaiKYxuVnzRVF9/0f7Bg== -"@bazel/rollup@5.4.0": - version "5.4.0" - resolved "https://registry.yarnpkg.com/@bazel/rollup/-/rollup-5.4.0.tgz#dc580e8d134222fa3058c1287554c04539118aa3" - integrity sha512-azN81aPnoqffRSvaWAJGeUyQEe43OlNcN7PgOIQzIyMcE2psXfJ0TaHgAV7vZKBjXADZGD4uKJNAeYU5woCZfg== +"@bazel/rollup@5.4.1": + version "5.4.1" + resolved "https://registry.yarnpkg.com/@bazel/rollup/-/rollup-5.4.1.tgz#3a79e6fd58e0afb540d2b975ecc2b8cb97374a07" + integrity sha512-HT+C2r9Q3/5Lzy6i31zV+a4s32VqhyUYpqUhdyTWWshAmKnkjE4T0KDKBGfZ6sBveTnbnEL2Y+822FAv05gPgg== dependencies: - "@bazel/worker" "5.4.0" - -"@bazel/runfiles@5.4.0": - version "5.4.0" - resolved "https://registry.yarnpkg.com/@bazel/runfiles/-/runfiles-5.4.0.tgz#3783148dec286d4b8a97c50573d22528a0f7c424" - integrity sha512-Kj461fH+fFhyp0iN/7yKS8hMOx27o4DdAK5a/PaFLG9IYdPxICIWBMhS8ccdr21R2LZKxHrjWdh9vRnuuKZtKw== + "@bazel/worker" "5.4.1" "@bazel/runfiles@5.4.1": version "5.4.1" resolved "https://registry.yarnpkg.com/@bazel/runfiles/-/runfiles-5.4.1.tgz#d85f3f5d5bd0b7b3f15ee9a5d3ad822cfb98c5f8" integrity sha512-P3ieXEcUKsycQcSfh6WqrESxvdd3eVwByQtK9wD0Xq2gvdBQlbl5tSNwyhKf41fWKyS6n4ZCLv7TXhFfMxZj9Q== -"@bazel/terser@5.4.0": - version "5.4.0" - resolved "https://registry.yarnpkg.com/@bazel/terser/-/terser-5.4.0.tgz#46b37a26715c1cfffb67015cd663eacfafe1af52" - integrity sha512-mJYBvhRBU0xfr4vEHJ7EYU3gwfL5tJ/NvCclU7jgMngw4C/tsjbPOIJaAIDUdmmFqjpq3xdUceameqT+3psnwA== - "@bazel/terser@5.4.1": version "5.4.1" resolved "https://registry.yarnpkg.com/@bazel/terser/-/terser-5.4.1.tgz#1a863c53f89f9882dcb489ec6ee1d1e64de8dd78" @@ -1474,13 +1445,6 @@ source-map-support "0.5.9" tsutils "3.21.0" -"@bazel/worker@5.4.0": - version "5.4.0" - resolved "https://registry.yarnpkg.com/@bazel/worker/-/worker-5.4.0.tgz#ce50e34951ccf7233b651f0be665bbd43d7ed7f1" - integrity sha512-Rtkol9WoYs0NCZl1wt4Q8T7Rs0wbQjIvFiJzVeeoC/00TG0e/qi4mYE5iQwUJmO8st3N8VnaWz2N31UHc6yhRA== - dependencies: - google-protobuf "^3.6.1" - "@bazel/worker@5.4.1": version "5.4.1" resolved "https://registry.yarnpkg.com/@bazel/worker/-/worker-5.4.1.tgz#7b7fbc329b81f8aef308c14999618be67a741b19" @@ -15402,6 +15366,11 @@ typescript@4.5.5, typescript@~4.5.2: resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.5.5.tgz#d8c953832d28924a9e3d37c73d729c846c5896f3" integrity sha512-TCTIul70LyWe6IJWT8QSYeA54WQe8EjQFU4wY52Fasj5UKx88LNYKCgBEHcOMOrFF1rKGbD8v/xcNWVUq9SymA== +typescript@4.7.0-beta: + version "4.7.0-beta" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.7.0-beta.tgz#15952f24d4177479ca3d19f09436ad8c69a30563" + integrity sha512-m+CNL8lzHyHDxYYDTI+pm5hw5/bufYVGan2bokPyJY/y9C/4W/PCWMtYZ0vV9fLXbEL57elMeoaz9Evxs8UQ+A== + typescript@^3.9.10, typescript@^3.9.5, typescript@^3.9.7: version "3.9.10" resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.9.10.tgz#70f3910ac7a51ed6bef79da7800690b19bf778b8"