From 9993c723359dad79e1162ec728572f7f6c817f5c Mon Sep 17 00:00:00 2001 From: Igor Minar Date: Thu, 27 Sep 2018 16:47:19 -0700 Subject: [PATCH] feat: add support for TypeScript 3.1 (#26151) PR Close #26151 --- integration/typings_test_ts27/tsconfig.json | 24 --------- integration/typings_test_ts28/include-all.ts | 49 ------------------- integration/typings_test_ts28/package.json | 31 ------------ .../include-all.ts | 0 .../package.json | 4 +- .../tsconfig.json | 2 +- package.json | 2 +- packages/bazel/package.json | 2 +- packages/compiler-cli/package.json | 2 +- .../compiler-cli/src/transformers/program.ts | 4 +- packages/core/src/sanitization/inert_body.ts | 2 +- .../back_patch_types_specs.ts | 10 ++-- .../elements/src/create-custom-element.ts | 2 +- packages/elements/src/utils.ts | 4 +- .../src/browser/browser_adapter.ts | 4 +- .../platform-browser/src/dom/dom_adapter.ts | 2 +- .../platform-server/src/domino_adapter.ts | 2 +- tools/public_api_guard/common/http.d.ts | 4 +- tools/public_api_guard/core/core.d.ts | 4 +- tools/ts-api-guardian/package.json | 4 +- tools/ts-api-guardian/yarn.lock | 6 +-- yarn.lock | 6 +-- 22 files changed, 34 insertions(+), 136 deletions(-) delete mode 100644 integration/typings_test_ts27/tsconfig.json delete mode 100644 integration/typings_test_ts28/include-all.ts delete mode 100644 integration/typings_test_ts28/package.json rename integration/{typings_test_ts27 => typings_test_ts31}/include-all.ts (100%) rename integration/{typings_test_ts27 => typings_test_ts31}/package.json (94%) rename integration/{typings_test_ts28 => typings_test_ts31}/tsconfig.json (90%) diff --git a/integration/typings_test_ts27/tsconfig.json b/integration/typings_test_ts27/tsconfig.json deleted file mode 100644 index 55de6011ac..0000000000 --- a/integration/typings_test_ts27/tsconfig.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "compilerOptions": { - "emitDecoratorMetadata": true, - "experimentalDecorators": true, - "module": "commonjs", - "moduleResolution": "node", - "outDir": "../../dist/typings_test_ts27/", - "rootDir": ".", - "target": "es5", - "lib": [ - "es5", - "dom", - "es2015.collection", - "es2015.iterable", - "es2015.promise" - ], - "types": [], - "strictNullChecks": true - }, - "files": [ - "include-all.ts", - "node_modules/@types/jasmine/index.d.ts" - ] -} diff --git a/integration/typings_test_ts28/include-all.ts b/integration/typings_test_ts28/include-all.ts deleted file mode 100644 index ca81c56472..0000000000 --- a/integration/typings_test_ts28/include-all.ts +++ /dev/null @@ -1,49 +0,0 @@ -/** - * @license - * Copyright Google Inc. 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 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 http from '@angular/http'; -import * as httpTesting from '@angular/http/testing'; -import * as platformBrowser from '@angular/platform-browser'; -import * as platformBrowserTesting from '@angular/platform-browser/testing'; -import * as platformBrowserDynamic from '@angular/platform-browser-dynamic'; -import * as platformServer from '@angular/platform-server'; -import * as platformServerTesting from '@angular/platform-server/testing'; -import * as platformWebworker from '@angular/platform-webworker'; -import * as platformWebworkerDynamic from '@angular/platform-webworker-dynamic'; -import * as router from '@angular/router'; -import * as routerTesting from '@angular/router/testing'; -import * as serviceWorker from '@angular/service-worker'; -import * as upgrade from '@angular/upgrade'; - -export default { - compiler, - compilerTesting, - core, - coreTesting, - elements, - forms, - http, - httpTesting, - platformBrowser, - platformBrowserTesting, - platformBrowserDynamic, - platformServer, - platformServerTesting, - platformWebworker, - platformWebworkerDynamic, - router, - routerTesting, - serviceWorker, - upgrade, -}; diff --git a/integration/typings_test_ts28/package.json b/integration/typings_test_ts28/package.json deleted file mode 100644 index 10a38622bd..0000000000 --- a/integration/typings_test_ts28/package.json +++ /dev/null @@ -1,31 +0,0 @@ -{ - "name": "angular-integration", - "description": "Assert that users with TypeScript 2.8 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/http": "file:../../dist/packages-dist/http", - "@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/platform-webworker": "file:../../dist/packages-dist/platform-webworker", - "@angular/platform-webworker-dynamic": "file:../../dist/packages-dist/platform-webworker-dynamic", - "@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": "2.5.41", - "rxjs": "file:../../node_modules/rxjs", - "typescript": "2.8.x", - "zone.js": "file:../../node_modules/zone.js" - }, - "scripts": { - "test": "tsc" - } -} diff --git a/integration/typings_test_ts27/include-all.ts b/integration/typings_test_ts31/include-all.ts similarity index 100% rename from integration/typings_test_ts27/include-all.ts rename to integration/typings_test_ts31/include-all.ts diff --git a/integration/typings_test_ts27/package.json b/integration/typings_test_ts31/package.json similarity index 94% rename from integration/typings_test_ts27/package.json rename to integration/typings_test_ts31/package.json index f601b04922..752c3a2c59 100644 --- a/integration/typings_test_ts27/package.json +++ b/integration/typings_test_ts31/package.json @@ -1,6 +1,6 @@ { "name": "angular-integration", - "description": "Assert that users with TypeScript 2.7 can type-check an Angular application", + "description": "Assert that users with TypeScript 3.0 can type-check an Angular application", "version": "0.0.0", "license": "MIT", "dependencies": { @@ -22,7 +22,7 @@ "@angular/upgrade": "file:../../dist/packages-dist/upgrade", "@types/jasmine": "2.5.41", "rxjs": "file:../../node_modules/rxjs", - "typescript": "2.7.x", + "typescript": "3.1.x", "zone.js": "file:../../node_modules/zone.js" }, "scripts": { diff --git a/integration/typings_test_ts28/tsconfig.json b/integration/typings_test_ts31/tsconfig.json similarity index 90% rename from integration/typings_test_ts28/tsconfig.json rename to integration/typings_test_ts31/tsconfig.json index 165bd7a957..0c58197db3 100644 --- a/integration/typings_test_ts28/tsconfig.json +++ b/integration/typings_test_ts31/tsconfig.json @@ -4,7 +4,7 @@ "experimentalDecorators": true, "module": "commonjs", "moduleResolution": "node", - "outDir": "../../dist/typings_test_ts28/", + "outDir": "../../dist/typings_test_ts30/", "rootDir": ".", "target": "es5", "lib": [ diff --git a/package.json b/package.json index 2830cefd58..3a6f31440b 100644 --- a/package.json +++ b/package.json @@ -127,7 +127,7 @@ "tslint": "5.7.0", "tslint-eslint-rules": "4.1.1", "tsutils": "2.20.0", - "typescript": "~3.0.1", + "typescript": "~3.1.1", "uglify-es": "^3.3.9", "universal-analytics": "0.4.15", "vlq": "0.2.2", diff --git a/packages/bazel/package.json b/packages/bazel/package.json index e889a37e2b..a93d4905a6 100644 --- a/packages/bazel/package.json +++ b/packages/bazel/package.json @@ -11,7 +11,7 @@ }, "peerDependencies": { "@angular/compiler-cli": "0.0.0-PLACEHOLDER", - "typescript": ">=3.0.1 <3.1" + "typescript": ">=3.1.1 <3.2" }, "repository": { "type": "git", diff --git a/packages/compiler-cli/package.json b/packages/compiler-cli/package.json index 93a3a281d4..63912e6d54 100644 --- a/packages/compiler-cli/package.json +++ b/packages/compiler-cli/package.json @@ -23,7 +23,7 @@ }, "peerDependencies": { "@angular/compiler": "0.0.0-PLACEHOLDER", - "typescript": ">=3.0.1 <3.1" + "typescript": ">=3.1.1 <3.2" }, "engines" : { "node" : ">=8.0" diff --git a/packages/compiler-cli/src/transformers/program.ts b/packages/compiler-cli/src/transformers/program.ts index 3cf68e000d..79b3ee4f18 100644 --- a/packages/compiler-cli/src/transformers/program.ts +++ b/packages/compiler-cli/src/transformers/program.ts @@ -72,14 +72,14 @@ const defaultEmitCallback: TsEmitCallback = * Minimum supported TypeScript version * ∀ supported typescript version v, v >= MIN_TS_VERSION */ -const MIN_TS_VERSION = '3.0.1'; +const MIN_TS_VERSION = '3.1.1'; /** * Supremum of supported TypeScript versions * ∀ supported typescript version v, v < MAX_TS_VERSION * MAX_TS_VERSION is not considered as a supported TypeScript version */ -const MAX_TS_VERSION = '3.1.0'; +const MAX_TS_VERSION = '3.2.0'; class AngularCompilerProgram implements Program { private rootNames: string[]; diff --git a/packages/core/src/sanitization/inert_body.ts b/packages/core/src/sanitization/inert_body.ts index a0da7d1bf6..e3bde269c7 100644 --- a/packages/core/src/sanitization/inert_body.ts +++ b/packages/core/src/sanitization/inert_body.ts @@ -151,7 +151,7 @@ export class InertBodyHelper { el.removeAttribute(attrName); } } - let childNode = el.firstChild; + let childNode = el.firstChild as Node | null; while (childNode) { if (childNode.nodeType === Node.ELEMENT_NODE) this.stripCustomNsAttrs(childNode as Element); childNode = childNode.nextSibling; diff --git a/packages/core/test/render3/compiler_canonical/back_patch_types_specs.ts b/packages/core/test/render3/compiler_canonical/back_patch_types_specs.ts index 1f8a28d77c..28b0a35282 100644 --- a/packages/core/test/render3/compiler_canonical/back_patch_types_specs.ts +++ b/packages/core/test/render3/compiler_canonical/back_patch_types_specs.ts @@ -116,10 +116,12 @@ function ngBackPatch_node_modules_libB_module_LibAModule() { export const AppModuleFactory: NgModuleFactory&{patchedDeps: boolean} = { moduleType: AppModule, - patchedDeps: false, - create(parentInjector: Injector | null): NgModuleRef{ - this.patchedDeps && ngBackPatch_node_modules_libB_module() && (this.patchedDeps = true); - return details_elided;} + patchedDeps: false, create(parentInjector: Injector | null): NgModuleRef{ + if (!this.patchedDeps) { + ngBackPatch_node_modules_libB_module(); + this.patchedDeps = true; + } return details_elided; + } }; // BEGIN FILE: src/app.ngfactory.ts diff --git a/packages/elements/src/create-custom-element.ts b/packages/elements/src/create-custom-element.ts index a5f1f1575a..7857bad5df 100644 --- a/packages/elements/src/create-custom-element.ts +++ b/packages/elements/src/create-custom-element.ts @@ -165,7 +165,7 @@ export function createCustomElement

( // Listen for events from the strategy and dispatch them as custom events this.ngElementEventsSubscription = this.ngElementStrategy.events.subscribe(e => { - const customEvent = createCustomEvent(this.ownerDocument, e.name, e.value); + const customEvent = createCustomEvent(this.ownerDocument !, e.name, e.value); this.dispatchEvent(customEvent); }); } diff --git a/packages/elements/src/utils.ts b/packages/elements/src/utils.ts index bd05304cd0..0491485777 100644 --- a/packages/elements/src/utils.ts +++ b/packages/elements/src/utils.ts @@ -74,8 +74,8 @@ export function createCustomEvent(doc: Document, name: string, detail: any): Cus /** * Check whether the input is an `Element`. */ -export function isElement(node: Node): node is Element { - return node.nodeType === Node.ELEMENT_NODE; +export function isElement(node: Node | null): node is Element { + return !!node && node.nodeType === Node.ELEMENT_NODE; } /** diff --git a/packages/platform-browser/src/browser/browser_adapter.ts b/packages/platform-browser/src/browser/browser_adapter.ts index e11f969822..59de0acd3a 100644 --- a/packages/platform-browser/src/browser/browser_adapter.ts +++ b/packages/platform-browser/src/browser/browser_adapter.ts @@ -118,7 +118,7 @@ export class BrowserDomAdapter extends GenericBrowserDomAdapter { get attrToPropMap(): any { return _attrToPropMap; } contains(nodeA: any, nodeB: any): boolean { return nodeContains.call(nodeA, nodeB); } - querySelector(el: Element, selector: string): any { return el.querySelector(selector); } + querySelector(el: HTMLElement, selector: string): any { return el.querySelector(selector); } querySelectorAll(el: any, selector: string): any[] { return el.querySelectorAll(selector); } on(el: Node, evt: any, listener: any) { el.addEventListener(evt, listener, false); } onAndCancel(el: Node, evt: any, listener: any): Function { @@ -276,7 +276,7 @@ export class BrowserDomAdapter extends GenericBrowserDomAdapter { getAttribute(element: Element, attribute: string): string|null { return element.getAttribute(attribute); } - getAttributeNS(element: Element, ns: string, name: string): string { + getAttributeNS(element: Element, ns: string, name: string): string|null { return element.getAttributeNS(ns, name); } setAttribute(element: Element, name: string, value: string) { element.setAttribute(name, value); } diff --git a/packages/platform-browser/src/dom/dom_adapter.ts b/packages/platform-browser/src/dom/dom_adapter.ts index 5057f6dfbb..f6a4b60c82 100644 --- a/packages/platform-browser/src/dom/dom_adapter.ts +++ b/packages/platform-browser/src/dom/dom_adapter.ts @@ -119,7 +119,7 @@ export abstract class DomAdapter { abstract hasAttribute(element: any, attribute: string): boolean; abstract hasAttributeNS(element: any, ns: string, attribute: string): boolean; abstract getAttribute(element: any, attribute: string): string|null; - abstract getAttributeNS(element: any, ns: string, attribute: string): string; + abstract getAttributeNS(element: any, ns: string, attribute: string): string|null; abstract setAttribute(element: any, name: string, value: string): any; abstract setAttributeNS(element: any, ns: string, name: string, value: string): any; abstract removeAttribute(element: any, attribute: string): any; diff --git a/packages/platform-server/src/domino_adapter.ts b/packages/platform-server/src/domino_adapter.ts index 17bf3c4fc9..5144532d83 100644 --- a/packages/platform-server/src/domino_adapter.ts +++ b/packages/platform-server/src/domino_adapter.ts @@ -135,7 +135,7 @@ export class DominoAdapter extends BrowserDomAdapter { } getBaseHref(doc: Document): string { - const base = this.querySelector(doc.documentElement, 'base'); + const base = this.querySelector(doc.documentElement !, 'base'); let href = ''; if (base) { href = this.getHref(base); diff --git a/tools/public_api_guard/common/http.d.ts b/tools/public_api_guard/common/http.d.ts index 95a42ec225..e416f98bfa 100644 --- a/tools/public_api_guard/common/http.d.ts +++ b/tools/public_api_guard/common/http.d.ts @@ -1497,8 +1497,8 @@ export interface HttpDownloadProgressEvent extends HttpProgressEvent { export declare class HttpErrorResponse extends HttpResponseBase implements Error { readonly error: any | null; readonly message: string; - readonly name: string; - readonly ok: boolean; + readonly name = "HttpErrorResponse"; + readonly ok = false; constructor(init: { error?: any; headers?: HttpHeaders; diff --git a/tools/public_api_guard/core/core.d.ts b/tools/public_api_guard/core/core.d.ts index d710f2e04c..41d094a89f 100644 --- a/tools/public_api_guard/core/core.d.ts +++ b/tools/public_api_guard/core/core.d.ts @@ -26,7 +26,7 @@ export declare const APP_ID: InjectionToken; export declare const APP_INITIALIZER: InjectionToken<(() => void)[]>; export declare class ApplicationInitStatus { - readonly done: boolean; + readonly done = false; readonly donePromise: Promise; constructor(appInits: (() => any)[]); } @@ -624,7 +624,7 @@ export declare abstract class Query { export declare class QueryList { readonly changes: Observable; - readonly dirty: boolean; + readonly dirty = true; readonly first: T; readonly last: T; readonly length: number; diff --git a/tools/ts-api-guardian/package.json b/tools/ts-api-guardian/package.json index 51c6452cf7..74f4bc4cb1 100644 --- a/tools/ts-api-guardian/package.json +++ b/tools/ts-api-guardian/package.json @@ -11,7 +11,7 @@ "test": "test" }, "peerDependencies": { - "typescript": "^3.0.1" + "typescript": "~3.1.1" }, "dependencies": { "chalk": "^2.3.1", @@ -24,7 +24,7 @@ "@types/node": "^10.9.2", "chai": "^4.1.2", "jasmine": "^3.1.0", - "typescript": "~3.0.1" + "typescript": "~3.1.1" }, "repository": {}, "keywords": [ diff --git a/tools/ts-api-guardian/yarn.lock b/tools/ts-api-guardian/yarn.lock index f856bf73be..6803495652 100644 --- a/tools/ts-api-guardian/yarn.lock +++ b/tools/ts-api-guardian/yarn.lock @@ -165,9 +165,9 @@ type-detect@^4.0.0: version "4.0.8" resolved "https://registry.yarnpkg.com/type-detect/-/type-detect-4.0.8.tgz#7646fb5f18871cfbb7749e69bd39a6388eb7450c" -typescript@~3.0.1: - version "3.0.1" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.0.1.tgz#43738f29585d3a87575520a4b93ab6026ef11fdb" +typescript@~3.1.1: + version "3.1.1" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.1.1.tgz#3362ba9dd1e482ebb2355b02dfe8bcd19a2c7c96" wrappy@1: version "1.0.2" diff --git a/yarn.lock b/yarn.lock index be35edaa17..43799e43fa 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7151,9 +7151,9 @@ typedarray@^0.0.6: version "2.7.2" resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.7.2.tgz#2d615a1ef4aee4f574425cdff7026edf81919836" -typescript@~3.0.1: - version "3.0.1" - resolved "https://registry.yarnpkg.com/npm/OBG-NPM/typescript/-/typescript-3.0.1.tgz#43738f29585d3a87575520a4b93ab6026ef11fdb" +typescript@~3.1.1: + version "3.1.1" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.1.1.tgz#3362ba9dd1e482ebb2355b02dfe8bcd19a2c7c96" uglify-es@^3.3.9: version "3.3.9"