From 07c0708ae9ddd04390473e2187a8c55b49d94f4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mi=C5=A1ko=20Hevery?= Date: Thu, 27 Apr 2017 13:39:21 -0700 Subject: [PATCH] fix: strictNullCheck support. (Fix #16357) --- integration/typings_test_ts21/include-all.ts | 2 + integration/typings_test_ts21/package.json | 1 + integration/typings_test_ts21/tsconfig.json | 4 +- integration/typings_test_ts22/include-all.ts | 2 + integration/typings_test_ts22/package.json | 1 + integration/typings_test_ts22/tsconfig.json | 5 +- packages/forms/src/model.ts | 60 ++++++++++---------- 7 files changed, 39 insertions(+), 36 deletions(-) diff --git a/integration/typings_test_ts21/include-all.ts b/integration/typings_test_ts21/include-all.ts index 499b6e60240373..916cf719e4ec2a 100644 --- a/integration/typings_test_ts21/include-all.ts +++ b/integration/typings_test_ts21/include-all.ts @@ -9,6 +9,7 @@ import * as compiler from '@angular/compiler'; import * as compilerTesting from '@angular/compiler/testing'; import * as coreTesting from '@angular/core'; +import * as forms from '@angular/forms'; import * as core from '@angular/core/testing'; import * as httpTesting from '@angular/http'; import * as http from '@angular/http/testing'; @@ -26,6 +27,7 @@ export default { compilerTesting, core, coreTesting, + forms, http, httpTesting, platformBrowser, diff --git a/integration/typings_test_ts21/package.json b/integration/typings_test_ts21/package.json index c051e33df60e96..98fabcb9119428 100644 --- a/integration/typings_test_ts21/package.json +++ b/integration/typings_test_ts21/package.json @@ -9,6 +9,7 @@ "@angular/compiler": "file:../../dist/packages-dist/compiler", "@angular/compiler-cli": "file:../../dist/packages-dist/compiler-cli", "@angular/core": "file:../../dist/packages-dist/core", + "@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", diff --git a/integration/typings_test_ts21/tsconfig.json b/integration/typings_test_ts21/tsconfig.json index 7c9539fff666a9..171acb2444874d 100644 --- a/integration/typings_test_ts21/tsconfig.json +++ b/integration/typings_test_ts21/tsconfig.json @@ -8,9 +8,7 @@ "rootDir": ".", "target": "es5", "lib": ["es5", "dom", "es2015.collection", "es2015.iterable", "es2015.promise"], - "types": [], - // TODO(i): strictNullChecks should turned on but are temporarily disabled due to #15432 - "strictNullChecks": false + "types": [] }, "files": [ "include-all.ts", diff --git a/integration/typings_test_ts22/include-all.ts b/integration/typings_test_ts22/include-all.ts index 499b6e60240373..9a869b7ce2e328 100644 --- a/integration/typings_test_ts22/include-all.ts +++ b/integration/typings_test_ts22/include-all.ts @@ -10,6 +10,7 @@ import * as compiler from '@angular/compiler'; import * as compilerTesting from '@angular/compiler/testing'; import * as coreTesting from '@angular/core'; import * as core from '@angular/core/testing'; +import * as forms from '@angular/forms'; import * as httpTesting from '@angular/http'; import * as http from '@angular/http/testing'; import * as platformBrowserTesting from '@angular/platform-browser'; @@ -26,6 +27,7 @@ export default { compilerTesting, core, coreTesting, + forms, http, httpTesting, platformBrowser, diff --git a/integration/typings_test_ts22/package.json b/integration/typings_test_ts22/package.json index 2152eb41e9665c..45092aa006e0e7 100644 --- a/integration/typings_test_ts22/package.json +++ b/integration/typings_test_ts22/package.json @@ -9,6 +9,7 @@ "@angular/compiler": "file:../../dist/packages-dist/compiler", "@angular/compiler-cli": "file:../../dist/packages-dist/compiler-cli", "@angular/core": "file:../../dist/packages-dist/core", + "@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", diff --git a/integration/typings_test_ts22/tsconfig.json b/integration/typings_test_ts22/tsconfig.json index 02f12fe4b7439f..d9603e8dce7994 100644 --- a/integration/typings_test_ts22/tsconfig.json +++ b/integration/typings_test_ts22/tsconfig.json @@ -15,11 +15,10 @@ "es2015.promise" ], "types": [], - // TODO(i): strictNullChecks should turned on but are temporarily disabled due to #15432 - "strictNullChecks": false + "strictNullChecks": true }, "files": [ "include-all.ts", "node_modules/@types/jasmine/index.d.ts" ] -} \ No newline at end of file +} diff --git a/packages/forms/src/model.ts b/packages/forms/src/model.ts index d072b7ed056a8e..ce1c2fbea042b8 100644 --- a/packages/forms/src/model.ts +++ b/packages/forms/src/model.ts @@ -659,17 +659,17 @@ export class FormControl extends AbstractControl { * If `emitViewToModelChange` is `true`, an ngModelChange event will be fired to update the * model. This is the default behavior if `emitViewToModelChange` is not specified. */ - setValue(value: any, {onlySelf, emitEvent, emitModelToViewChange, emitViewToModelChange}: { + setValue(value: any, options: { onlySelf?: boolean, emitEvent?: boolean, emitModelToViewChange?: boolean, emitViewToModelChange?: boolean } = {}): void { this._value = value; - if (this._onChange.length && emitModelToViewChange !== false) { - this._onChange.forEach((changeFn) => changeFn(this._value, emitViewToModelChange !== false)); + if (this._onChange.length && options.emitModelToViewChange !== false) { + this._onChange.forEach((changeFn) => changeFn(this._value, options.emitViewToModelChange !== false)); } - this.updateValueAndValidity({onlySelf, emitEvent}); + this.updateValueAndValidity(options); } /** @@ -716,12 +716,12 @@ export class FormControl extends AbstractControl { * console.log(this.control.status); // 'DISABLED' * ``` */ - reset(formState: any = null, {onlySelf, emitEvent}: {onlySelf?: boolean, + reset(formState: any = null, options: {onlySelf?: boolean, emitEvent?: boolean} = {}): void { this._applyFormState(formState); - this.markAsPristine({onlySelf}); - this.markAsUntouched({onlySelf}); - this.setValue(this._value, {onlySelf, emitEvent}); + this.markAsPristine(options); + this.markAsUntouched(options); + this.setValue(this._value, options); } /** @@ -916,13 +916,13 @@ export class FormGroup extends AbstractControl { */ setValue( value: {[key: string]: any}, - {onlySelf, emitEvent}: {onlySelf?: boolean, emitEvent?: boolean} = {}): void { + options: {onlySelf?: boolean, emitEvent?: boolean} = {}): void { this._checkAllValuesPresent(value); Object.keys(value).forEach(name => { this._throwIfControlMissing(name); - this.controls[name].setValue(value[name], {onlySelf: true, emitEvent}); + this.controls[name].setValue(value[name], {onlySelf: true, emitEvent: options.emitEvent}); }); - this.updateValueAndValidity({onlySelf, emitEvent}); + this.updateValueAndValidity(options); } /** @@ -948,13 +948,13 @@ export class FormGroup extends AbstractControl { */ patchValue( value: {[key: string]: any}, - {onlySelf, emitEvent}: {onlySelf?: boolean, emitEvent?: boolean} = {}): void { + options: {onlySelf?: boolean, emitEvent?: boolean} = {}): void { Object.keys(value).forEach(name => { if (this.controls[name]) { - this.controls[name].patchValue(value[name], {onlySelf: true, emitEvent}); + this.controls[name].patchValue(value[name], {onlySelf: true, emitEvent: options.emitEvent}); } }); - this.updateValueAndValidity({onlySelf, emitEvent}); + this.updateValueAndValidity(options); } /** @@ -989,14 +989,14 @@ export class FormGroup extends AbstractControl { * console.log(this.form.get('first').status); // 'DISABLED' * ``` */ - reset(value: any = {}, {onlySelf, emitEvent}: {onlySelf?: boolean, emitEvent?: boolean} = {}): + reset(value: any = {}, options: {onlySelf?: boolean, emitEvent?: boolean} = {}): void { this._forEachChild((control: AbstractControl, name: string) => { - control.reset(value[name], {onlySelf: true, emitEvent}); + control.reset(value[name], {onlySelf: true, emitEvent: options.emitEvent}); }); - this.updateValueAndValidity({onlySelf, emitEvent}); - this._updatePristine({onlySelf}); - this._updateTouched({onlySelf}); + this.updateValueAndValidity(options); + this._updatePristine(options); + this._updateTouched(options); } /** @@ -1222,14 +1222,14 @@ export class FormArray extends AbstractControl { * console.log(arr.value); // ['Nancy', 'Drew'] * ``` */ - setValue(value: any[], {onlySelf, emitEvent}: {onlySelf?: boolean, emitEvent?: boolean} = {}): + setValue(value: any[], options: {onlySelf?: boolean, emitEvent?: boolean} = {}): void { this._checkAllValuesPresent(value); value.forEach((newValue: any, index: number) => { this._throwIfControlMissing(index); - this.at(index).setValue(newValue, {onlySelf: true, emitEvent}); + this.at(index).setValue(newValue, {onlySelf: true, emitEvent: options.emitEvent}); }); - this.updateValueAndValidity({onlySelf, emitEvent}); + this.updateValueAndValidity(options); } /** @@ -1252,14 +1252,14 @@ export class FormArray extends AbstractControl { * console.log(arr.value); // ['Nancy', null] * ``` */ - patchValue(value: any[], {onlySelf, emitEvent}: {onlySelf?: boolean, emitEvent?: boolean} = {}): + patchValue(value: any[], options: {onlySelf?: boolean, emitEvent?: boolean} = {}): void { value.forEach((newValue: any, index: number) => { if (this.at(index)) { - this.at(index).patchValue(newValue, {onlySelf: true, emitEvent}); + this.at(index).patchValue(newValue, {onlySelf: true, emitEvent: options.emitEvent}); } }); - this.updateValueAndValidity({onlySelf, emitEvent}); + this.updateValueAndValidity(options); } /** @@ -1293,14 +1293,14 @@ export class FormArray extends AbstractControl { * console.log(this.arr.get(0).status); // 'DISABLED' * ``` */ - reset(value: any = [], {onlySelf, emitEvent}: {onlySelf?: boolean, emitEvent?: boolean} = {}): + reset(value: any = [], options: {onlySelf?: boolean, emitEvent?: boolean} = {}): void { this._forEachChild((control: AbstractControl, index: number) => { - control.reset(value[index], {onlySelf: true, emitEvent}); + control.reset(value[index], {onlySelf: true, emitEvent: options.emitEvent}); }); - this.updateValueAndValidity({onlySelf, emitEvent}); - this._updatePristine({onlySelf}); - this._updateTouched({onlySelf}); + this.updateValueAndValidity(options); + this._updatePristine(options); + this._updateTouched(options); } /**