fix: strictNullCheck support. (#16389) (#16389)

Fix #16357

Workaround for https://github.com/Microsoft/TypeScript/issues/10078

Closes #16389

PR Close #16389
This commit is contained in:
Miško Hevery 2017-04-27 13:39:21 -07:00 committed by Miško Hevery
parent c04e51cb15
commit 8c09d10ba9
8 changed files with 50 additions and 52 deletions

View File

@ -9,6 +9,7 @@
import * as compiler from '@angular/compiler'; import * as compiler from '@angular/compiler';
import * as compilerTesting from '@angular/compiler/testing'; import * as compilerTesting from '@angular/compiler/testing';
import * as coreTesting from '@angular/core'; import * as coreTesting from '@angular/core';
import * as forms from '@angular/forms';
import * as core from '@angular/core/testing'; import * as core from '@angular/core/testing';
import * as httpTesting from '@angular/http'; import * as httpTesting from '@angular/http';
import * as http from '@angular/http/testing'; import * as http from '@angular/http/testing';
@ -26,6 +27,7 @@ export default {
compilerTesting, compilerTesting,
core, core,
coreTesting, coreTesting,
forms,
http, http,
httpTesting, httpTesting,
platformBrowser, platformBrowser,

View File

@ -9,6 +9,7 @@
"@angular/compiler": "file:../../dist/packages-dist/compiler", "@angular/compiler": "file:../../dist/packages-dist/compiler",
"@angular/compiler-cli": "file:../../dist/packages-dist/compiler-cli", "@angular/compiler-cli": "file:../../dist/packages-dist/compiler-cli",
"@angular/core": "file:../../dist/packages-dist/core", "@angular/core": "file:../../dist/packages-dist/core",
"@angular/forms": "file:../../dist/packages-dist/forms",
"@angular/http": "file:../../dist/packages-dist/http", "@angular/http": "file:../../dist/packages-dist/http",
"@angular/platform-browser": "file:../../dist/packages-dist/platform-browser", "@angular/platform-browser": "file:../../dist/packages-dist/platform-browser",
"@angular/platform-browser-dynamic": "file:../../dist/packages-dist/platform-browser-dynamic", "@angular/platform-browser-dynamic": "file:../../dist/packages-dist/platform-browser-dynamic",

View File

@ -9,8 +9,7 @@
"target": "es5", "target": "es5",
"lib": ["es5", "dom", "es2015.collection", "es2015.iterable", "es2015.promise"], "lib": ["es5", "dom", "es2015.collection", "es2015.iterable", "es2015.promise"],
"types": [], "types": [],
// TODO(i): strictNullChecks should turned on but are temporarily disabled due to #15432 "strictNullChecks": true
"strictNullChecks": false
}, },
"files": [ "files": [
"include-all.ts", "include-all.ts",

View File

@ -10,6 +10,7 @@ import * as compiler from '@angular/compiler';
import * as compilerTesting from '@angular/compiler/testing'; import * as compilerTesting from '@angular/compiler/testing';
import * as coreTesting from '@angular/core'; import * as coreTesting from '@angular/core';
import * as core from '@angular/core/testing'; import * as core from '@angular/core/testing';
import * as forms from '@angular/forms';
import * as httpTesting from '@angular/http'; import * as httpTesting from '@angular/http';
import * as http from '@angular/http/testing'; import * as http from '@angular/http/testing';
import * as platformBrowserTesting from '@angular/platform-browser'; import * as platformBrowserTesting from '@angular/platform-browser';
@ -26,6 +27,7 @@ export default {
compilerTesting, compilerTesting,
core, core,
coreTesting, coreTesting,
forms,
http, http,
httpTesting, httpTesting,
platformBrowser, platformBrowser,

View File

@ -9,6 +9,7 @@
"@angular/compiler": "file:../../dist/packages-dist/compiler", "@angular/compiler": "file:../../dist/packages-dist/compiler",
"@angular/compiler-cli": "file:../../dist/packages-dist/compiler-cli", "@angular/compiler-cli": "file:../../dist/packages-dist/compiler-cli",
"@angular/core": "file:../../dist/packages-dist/core", "@angular/core": "file:../../dist/packages-dist/core",
"@angular/forms": "file:../../dist/packages-dist/forms",
"@angular/http": "file:../../dist/packages-dist/http", "@angular/http": "file:../../dist/packages-dist/http",
"@angular/platform-browser": "file:../../dist/packages-dist/platform-browser", "@angular/platform-browser": "file:../../dist/packages-dist/platform-browser",
"@angular/platform-browser-dynamic": "file:../../dist/packages-dist/platform-browser-dynamic", "@angular/platform-browser-dynamic": "file:../../dist/packages-dist/platform-browser-dynamic",

View File

@ -15,11 +15,10 @@
"es2015.promise" "es2015.promise"
], ],
"types": [], "types": [],
// TODO(i): strictNullChecks should turned on but are temporarily disabled due to #15432 "strictNullChecks": true
"strictNullChecks": false
}, },
"files": [ "files": [
"include-all.ts", "include-all.ts",
"node_modules/@types/jasmine/index.d.ts" "node_modules/@types/jasmine/index.d.ts"
] ]
} }

View File

@ -659,17 +659,18 @@ export class FormControl extends AbstractControl {
* If `emitViewToModelChange` is `true`, an ngModelChange event will be fired to update the * If `emitViewToModelChange` is `true`, an ngModelChange event will be fired to update the
* model. This is the default behavior if `emitViewToModelChange` is not specified. * model. This is the default behavior if `emitViewToModelChange` is not specified.
*/ */
setValue(value: any, {onlySelf, emitEvent, emitModelToViewChange, emitViewToModelChange}: { setValue(value: any, options: {
onlySelf?: boolean, onlySelf?: boolean,
emitEvent?: boolean, emitEvent?: boolean,
emitModelToViewChange?: boolean, emitModelToViewChange?: boolean,
emitViewToModelChange?: boolean emitViewToModelChange?: boolean
} = {}): void { } = {}): void {
this._value = value; this._value = value;
if (this._onChange.length && emitModelToViewChange !== false) { if (this._onChange.length && options.emitModelToViewChange !== false) {
this._onChange.forEach((changeFn) => changeFn(this._value, emitViewToModelChange !== false)); this._onChange.forEach(
(changeFn) => changeFn(this._value, options.emitViewToModelChange !== false));
} }
this.updateValueAndValidity({onlySelf, emitEvent}); this.updateValueAndValidity(options);
} }
/** /**
@ -716,12 +717,11 @@ export class FormControl extends AbstractControl {
* console.log(this.control.status); // 'DISABLED' * console.log(this.control.status); // 'DISABLED'
* ``` * ```
*/ */
reset(formState: any = null, {onlySelf, emitEvent}: {onlySelf?: boolean, reset(formState: any = null, options: {onlySelf?: boolean, emitEvent?: boolean} = {}): void {
emitEvent?: boolean} = {}): void {
this._applyFormState(formState); this._applyFormState(formState);
this.markAsPristine({onlySelf}); this.markAsPristine(options);
this.markAsUntouched({onlySelf}); this.markAsUntouched(options);
this.setValue(this._value, {onlySelf, emitEvent}); this.setValue(this._value, options);
} }
/** /**
@ -914,15 +914,14 @@ export class FormGroup extends AbstractControl {
* *
* ``` * ```
*/ */
setValue( setValue(value: {[key: string]: any}, options: {onlySelf?: boolean, emitEvent?: boolean} = {}):
value: {[key: string]: any}, void {
{onlySelf, emitEvent}: {onlySelf?: boolean, emitEvent?: boolean} = {}): void {
this._checkAllValuesPresent(value); this._checkAllValuesPresent(value);
Object.keys(value).forEach(name => { Object.keys(value).forEach(name => {
this._throwIfControlMissing(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);
} }
/** /**
@ -946,15 +945,14 @@ export class FormGroup extends AbstractControl {
* *
* ``` * ```
*/ */
patchValue( patchValue(value: {[key: string]: any}, options: {onlySelf?: boolean, emitEvent?: boolean} = {}):
value: {[key: string]: any}, void {
{onlySelf, emitEvent}: {onlySelf?: boolean, emitEvent?: boolean} = {}): void {
Object.keys(value).forEach(name => { Object.keys(value).forEach(name => {
if (this.controls[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 +987,13 @@ export class FormGroup extends AbstractControl {
* console.log(this.form.get('first').status); // 'DISABLED' * 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 {
void {
this._forEachChild((control: AbstractControl, name: string) => { 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.updateValueAndValidity(options);
this._updatePristine({onlySelf}); this._updatePristine(options);
this._updateTouched({onlySelf}); this._updateTouched(options);
} }
/** /**
@ -1222,14 +1219,13 @@ export class FormArray extends AbstractControl {
* console.log(arr.value); // ['Nancy', 'Drew'] * console.log(arr.value); // ['Nancy', 'Drew']
* ``` * ```
*/ */
setValue(value: any[], {onlySelf, emitEvent}: {onlySelf?: boolean, emitEvent?: boolean} = {}): setValue(value: any[], options: {onlySelf?: boolean, emitEvent?: boolean} = {}): void {
void {
this._checkAllValuesPresent(value); this._checkAllValuesPresent(value);
value.forEach((newValue: any, index: number) => { value.forEach((newValue: any, index: number) => {
this._throwIfControlMissing(index); 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 +1248,13 @@ export class FormArray extends AbstractControl {
* console.log(arr.value); // ['Nancy', null] * console.log(arr.value); // ['Nancy', null]
* ``` * ```
*/ */
patchValue(value: any[], {onlySelf, emitEvent}: {onlySelf?: boolean, emitEvent?: boolean} = {}): patchValue(value: any[], options: {onlySelf?: boolean, emitEvent?: boolean} = {}): void {
void {
value.forEach((newValue: any, index: number) => { value.forEach((newValue: any, index: number) => {
if (this.at(index)) { 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 +1288,13 @@ export class FormArray extends AbstractControl {
* console.log(this.arr.get(0).status); // 'DISABLED' * 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 {
void {
this._forEachChild((control: AbstractControl, index: number) => { 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.updateValueAndValidity(options);
this._updatePristine({onlySelf}); this._updatePristine(options);
this._updateTouched({onlySelf}); this._updateTouched(options);
} }
/** /**

View File

@ -179,18 +179,18 @@ export declare class FormArray extends AbstractControl {
at(index: number): AbstractControl; at(index: number): AbstractControl;
getRawValue(): any[]; getRawValue(): any[];
insert(index: number, control: AbstractControl): void; insert(index: number, control: AbstractControl): void;
patchValue(value: any[], {onlySelf, emitEvent}?: { patchValue(value: any[], options?: {
onlySelf?: boolean; onlySelf?: boolean;
emitEvent?: boolean; emitEvent?: boolean;
}): void; }): void;
push(control: AbstractControl): void; push(control: AbstractControl): void;
removeAt(index: number): void; removeAt(index: number): void;
reset(value?: any, {onlySelf, emitEvent}?: { reset(value?: any, options?: {
onlySelf?: boolean; onlySelf?: boolean;
emitEvent?: boolean; emitEvent?: boolean;
}): void; }): void;
setControl(index: number, control: AbstractControl): void; setControl(index: number, control: AbstractControl): void;
setValue(value: any[], {onlySelf, emitEvent}?: { setValue(value: any[], options?: {
onlySelf?: boolean; onlySelf?: boolean;
emitEvent?: boolean; emitEvent?: boolean;
}): void; }): void;
@ -231,11 +231,11 @@ export declare class FormControl extends AbstractControl {
}): void; }): void;
registerOnChange(fn: Function): void; registerOnChange(fn: Function): void;
registerOnDisabledChange(fn: (isDisabled: boolean) => void): void; registerOnDisabledChange(fn: (isDisabled: boolean) => void): void;
reset(formState?: any, {onlySelf, emitEvent}?: { reset(formState?: any, options?: {
onlySelf?: boolean; onlySelf?: boolean;
emitEvent?: boolean; emitEvent?: boolean;
}): void; }): void;
setValue(value: any, {onlySelf, emitEvent, emitModelToViewChange, emitViewToModelChange}?: { setValue(value: any, options?: {
onlySelf?: boolean; onlySelf?: boolean;
emitEvent?: boolean; emitEvent?: boolean;
emitModelToViewChange?: boolean; emitModelToViewChange?: boolean;
@ -289,20 +289,20 @@ export declare class FormGroup extends AbstractControl {
getRawValue(): any; getRawValue(): any;
patchValue(value: { patchValue(value: {
[key: string]: any; [key: string]: any;
}, {onlySelf, emitEvent}?: { }, options?: {
onlySelf?: boolean; onlySelf?: boolean;
emitEvent?: boolean; emitEvent?: boolean;
}): void; }): void;
registerControl(name: string, control: AbstractControl): AbstractControl; registerControl(name: string, control: AbstractControl): AbstractControl;
removeControl(name: string): void; removeControl(name: string): void;
reset(value?: any, {onlySelf, emitEvent}?: { reset(value?: any, options?: {
onlySelf?: boolean; onlySelf?: boolean;
emitEvent?: boolean; emitEvent?: boolean;
}): void; }): void;
setControl(name: string, control: AbstractControl): void; setControl(name: string, control: AbstractControl): void;
setValue(value: { setValue(value: {
[key: string]: any; [key: string]: any;
}, {onlySelf, emitEvent}?: { }, options?: {
onlySelf?: boolean; onlySelf?: boolean;
emitEvent?: boolean; emitEvent?: boolean;
}): void; }): void;