Skip to content

Commit 910c0d9

Browse files
mheveryvicb
authored andcommitted
fix(core): Update types for TypeScript nullability support (angular#15472)
1 parent 331b9f6 commit 910c0d9

File tree

84 files changed

+1288
-1261
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+1288
-1261
lines changed

modules/benchmarks/src/tree/ng2/init.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export function init(moduleRef: NgModuleRef<AppModule>) {
4040

4141
const injector = moduleRef.injector;
4242
appRef = injector.get(ApplicationRef);
43-
const numberOfChecksEl = document.getElementById('numberOfChecks');
43+
const numberOfChecksEl = document.getElementById('numberOfChecks') !;
4444

4545
tree = appRef.components[0].instance;
4646

modules/benchmarks/src/tree/util.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ export class TreeNode {
1313
children: TreeNode[];
1414

1515
constructor(
16-
public value: string, public depth: number, public maxDepth: number, public left: TreeNode,
17-
public right: TreeNode) {
16+
public value: string, public depth: number, public maxDepth: number,
17+
public left: TreeNode|null, public right: TreeNode|null) {
1818
this.transitiveChildCount = Math.pow(2, (this.maxDepth - this.depth + 1)) - 1;
19-
this.children = this.left ? [this.left, this.right] : [];
19+
this.children = this.left ? [this.left, this.right !] : [];
2020
}
2121

2222
// Needed for Polymer as it does not support ternary nor modulo operator

modules/benchmarks/src/util.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export function getStringParameter(name: string) {
3535
}
3636

3737
export function bindAction(selector: string, callback: () => void) {
38-
document.querySelector(selector).addEventListener('click', callback);
38+
document.querySelector(selector) !.addEventListener('click', callback);
3939
}
4040

4141

@@ -60,7 +60,7 @@ export function profile(create: () => void, destroy: () => void, name: string) {
6060
function urlParamsToForm() {
6161
const regex = /(\w+)=(\w+)/g;
6262
const search = decodeURIComponent(location.search);
63-
let match: any[];
63+
let match: any[]|null;
6464
while (match = regex.exec(search)) {
6565
const name = match[1];
6666
const value = match[2];
@@ -75,4 +75,4 @@ function urlParamsToForm() {
7575
}
7676
}
7777
}
78-
}
78+
}

packages/animations/src/animation_metadata.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export interface AnimationStyleMetadata extends AnimationMetadata {
9898
*/
9999
export interface AnimationAnimateMetadata extends AnimationMetadata {
100100
timings: string|number|AnimateTimings;
101-
styles: AnimationStyleMetadata|AnimationKeyframesSequenceMetadata;
101+
styles: AnimationStyleMetadata|AnimationKeyframesSequenceMetadata|null;
102102
}
103103

104104
/**
@@ -218,8 +218,8 @@ export function trigger(name: string, definitions: AnimationMetadata[]): Animati
218218
* @experimental Animation support is experimental.
219219
*/
220220
export function animate(
221-
timings: string | number, styles: AnimationStyleMetadata | AnimationKeyframesSequenceMetadata =
222-
null): AnimationAnimateMetadata {
221+
timings: string | number, styles: AnimationStyleMetadata | AnimationKeyframesSequenceMetadata |
222+
null = null): AnimationAnimateMetadata {
223223
return {type: AnimationMetadataType.Animate, styles: styles, timings: timings};
224224
}
225225

packages/compiler-cli/integrationtest/test/source_map_spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function getSourcePositionForStack(stack: string): {source: string, line: number
3030
const htmlLocations = stack
3131
.split('\n')
3232
// e.g. at View_MyComp_0 (...html:153:40)
33-
.map(line => /\((.*\.html):(\d+):(\d+)/.exec(line))
33+
.map(line => /\((.*\.html):(\d+):(\d+)/.exec(line) !)
3434
.filter(match => !!match)
3535
.map(match => ({
3636
source: match[1],

packages/compiler-cli/integrationtest/test/test_ngtools_api.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ function codeGenTest() {
6767
angularCompilerOptions: config.ngOptions,
6868

6969
// i18n options.
70-
i18nFormat: null,
71-
i18nFile: null,
72-
locale: null,
70+
i18nFormat: undefined,
71+
i18nFile: undefined,
72+
locale: undefined,
7373

7474
readResource: (fileName: string) => {
7575
readResources.push(fileName);
@@ -131,8 +131,8 @@ function i18nTest() {
131131
compilerOptions: config.parsed.options, program, host,
132132
angularCompilerOptions: config.ngOptions,
133133
i18nFormat: 'xlf',
134-
locale: null,
135-
outFile: null,
134+
locale: undefined,
135+
outFile: undefined,
136136
readResource: (fileName: string) => {
137137
readResources.push(fileName);
138138
return hostContext.readResource(fileName);

packages/compiler-cli/integrationtest/test/test_summaries.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ function main() {
3434
if (/.*\/node_modules\/.*/.test(fileName) && !/.*ngsummary\.json$/.test(fileName) &&
3535
!/package\.json$/.test(fileName)) {
3636
// Only allow to read summaries and package.json files from node_modules
37-
return null;
37+
// TODO (mhevery): Fix this. TypeScript.d.ts does not allow returning null.
38+
return null !;
3839
}
3940
readFiles.push(path.relative(basePath, fileName));
4041
return super.readFile(fileName);

packages/compiler-cli/integrationtest/test/util.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {platformServer} from '@angular/platform-server';
1313
import {MainModule} from '../src/module';
1414
import {MainModuleNgFactory} from '../src/module.ngfactory';
1515

16-
let mainModuleRef: NgModuleRef<MainModule> = null;
16+
let mainModuleRef: NgModuleRef<MainModule> = null !;
1717
beforeEach((done) => {
1818
platformServer().bootstrapModuleFactory(MainModuleNgFactory).then((moduleRef: any) => {
1919
mainModuleRef = moduleRef;
@@ -29,5 +29,5 @@ export function createComponent<C>(comp: {new (...args: any[]): C}): ComponentFi
2929
const moduleRef = createModule();
3030
const compRef =
3131
moduleRef.componentFactoryResolver.resolveComponentFactory(comp).create(moduleRef.injector);
32-
return new ComponentFixture(compRef, null, null);
32+
return new ComponentFixture(compRef, null, false);
3333
}

packages/compiler-cli/integrationtest/tsconfig-build.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
"target": "es5",
1111
"experimentalDecorators": true,
1212
"noImplicitAny": true,
13+
"strictNullChecks": true,
14+
"skipLibCheck": true,
1315
"moduleResolution": "node",
1416
"rootDir": "",
1517
"declaration": true,
@@ -32,4 +34,4 @@
3234
"benchmarks/src/largetable/ng2/index_aot.ts",
3335
"benchmarks/src/largetable/ng2_switch/index_aot.ts"
3436
]
35-
}
37+
}

packages/compiler-cli/src/ngtools_api.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ export interface NgTools_InternalApi_NG2_CodeGen_Options {
3232
angularCompilerOptions: AngularCompilerOptions;
3333

3434
// i18n options.
35-
i18nFormat: string;
36-
i18nFile: string;
37-
locale: string;
35+
i18nFormat?: string;
36+
i18nFile?: string;
37+
locale?: string;
3838

3939
readResource: (fileName: string) => Promise<string>;
4040

@@ -58,7 +58,7 @@ export interface NgTools_InternalApi_NG2_ExtractI18n_Options {
5858
program: ts.Program;
5959
host: ts.CompilerHost;
6060
angularCompilerOptions: AngularCompilerOptions;
61-
i18nFormat: string;
61+
i18nFormat?: string;
6262
readResource: (fileName: string) => Promise<string>;
6363
// Every new property under this line should be optional.
6464
locale?: string;

packages/compiler/src/view_compiler/view_compiler.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -644,8 +644,8 @@ class ViewBuilder implements TemplateAstVisitor, LocalResolver {
644644
return EventHandlerVars.event;
645645
}
646646
let currViewExpr: o.Expression = VIEW_VAR;
647-
for (let currBuilder: ViewBuilder = this; currBuilder;
648-
currBuilder = currBuilder.parent, currViewExpr = currViewExpr.prop('parent')) {
647+
for (let currBuilder: ViewBuilder = this; currBuilder; currBuilder = currBuilder.parent,
648+
currViewExpr = currViewExpr.prop('parent').cast(o.DYNAMIC_TYPE)) {
649649
// check references
650650
const refNodeIndex = currBuilder.refNodeIndices[name];
651651
if (refNodeIndex != null) {
@@ -717,7 +717,7 @@ class ViewBuilder implements TemplateAstVisitor, LocalResolver {
717717
let compBuilder: ViewBuilder = this;
718718
while (compBuilder.parent) {
719719
compBuilder = compBuilder.parent;
720-
compViewExpr = compViewExpr.prop('parent');
720+
compViewExpr = compViewExpr.prop('parent').cast(o.DYNAMIC_TYPE);
721721
}
722722
const pipeNodeIndex = compBuilder.purePipeNodeIndices[name];
723723
const pipeValueExpr: o.Expression =

packages/core/src/animation/animation_metadata_wrapped.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export interface AnimationStyleMetadata extends AnimationMetadata {
6262
*/
6363
export interface AnimationAnimateMetadata extends AnimationMetadata {
6464
timings: string|number|AnimateTimings;
65-
styles: AnimationStyleMetadata|AnimationKeyframesSequenceMetadata;
65+
styles: AnimationStyleMetadata|AnimationKeyframesSequenceMetadata|null;
6666
}
6767

6868
/**
@@ -86,8 +86,8 @@ export function trigger(name: string, definitions: AnimationMetadata[]): Animati
8686
* @deprecated This symbol has moved. Please Import from @angular/animations instead!
8787
*/
8888
export function animate(
89-
timings: string | number, styles: AnimationStyleMetadata | AnimationKeyframesSequenceMetadata =
90-
null): AnimationAnimateMetadata {
89+
timings: string | number, styles?: AnimationStyleMetadata |
90+
AnimationKeyframesSequenceMetadata): AnimationAnimateMetadata {
9191
return _animate(timings, styles);
9292
}
9393

packages/core/src/application_ref.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export function createPlatform(injector: Injector): PlatformRef {
9999
* @experimental APIs related to application bootstrap are currently under review.
100100
*/
101101
export function createPlatformFactory(
102-
parentPlatformFactory: (extraProviders?: Provider[]) => PlatformRef, name: string,
102+
parentPlatformFactory: ((extraProviders?: Provider[]) => PlatformRef) | null, name: string,
103103
providers: Provider[] = []): (extraProviders?: Provider[]) => PlatformRef {
104104
const marker = new InjectionToken(`Platform: ${name}`);
105105
return (extraProviders: Provider[] = []) => {
@@ -153,7 +153,7 @@ export function destroyPlatform(): void {
153153
*
154154
* @experimental APIs related to application bootstrap are currently under review.
155155
*/
156-
export function getPlatform(): PlatformRef {
156+
export function getPlatform(): PlatformRef|null {
157157
return _platform && !_platform.destroyed ? _platform : null;
158158
}
159159

@@ -278,10 +278,10 @@ export class PlatformRef_ extends PlatformRef {
278278
}
279279

280280
bootstrapModuleFactory<M>(moduleFactory: NgModuleFactory<M>): Promise<NgModuleRef<M>> {
281-
return this._bootstrapModuleFactoryWithZone(moduleFactory, null);
281+
return this._bootstrapModuleFactoryWithZone(moduleFactory);
282282
}
283283

284-
private _bootstrapModuleFactoryWithZone<M>(moduleFactory: NgModuleFactory<M>, ngZone: NgZone):
284+
private _bootstrapModuleFactoryWithZone<M>(moduleFactory: NgModuleFactory<M>, ngZone?: NgZone):
285285
Promise<NgModuleRef<M>> {
286286
// Note: We need to create the NgZone _before_ we instantiate the module,
287287
// as instantiating the module creates some providers eagerly.
@@ -299,7 +299,7 @@ export class PlatformRef_ extends PlatformRef {
299299
throw new Error('No ErrorHandler. Is platform module (BrowserModule) included?');
300300
}
301301
moduleRef.onDestroy(() => remove(this._modules, moduleRef));
302-
ngZone.onError.subscribe({next: (error: any) => { exceptionHandler.handleError(error); }});
302+
ngZone !.onError.subscribe({next: (error: any) => { exceptionHandler.handleError(error); }});
303303
return _callAndReportToErrorHandler(exceptionHandler, () => {
304304
const initStatus: ApplicationInitStatus = moduleRef.injector.get(ApplicationInitStatus);
305305
return initStatus.donePromise.then(() => {
@@ -312,12 +312,12 @@ export class PlatformRef_ extends PlatformRef {
312312

313313
bootstrapModule<M>(moduleType: Type<M>, compilerOptions: CompilerOptions|CompilerOptions[] = []):
314314
Promise<NgModuleRef<M>> {
315-
return this._bootstrapModuleWithZone(moduleType, compilerOptions, null);
315+
return this._bootstrapModuleWithZone(moduleType, compilerOptions);
316316
}
317317

318318
private _bootstrapModuleWithZone<M>(
319319
moduleType: Type<M>, compilerOptions: CompilerOptions|CompilerOptions[] = [],
320-
ngZone: NgZone = null): Promise<NgModuleRef<M>> {
320+
ngZone?: NgZone): Promise<NgModuleRef<M>> {
321321
const compilerFactory: CompilerFactory = this.injector.get(CompilerFactory);
322322
const compiler = compilerFactory.createCompiler(
323323
Array.isArray(compilerOptions) ? compilerOptions : [compilerOptions]);
@@ -500,7 +500,8 @@ export class ApplicationRef_ extends ApplicationRef {
500500
if (componentOrFactory instanceof ComponentFactory) {
501501
componentFactory = componentOrFactory;
502502
} else {
503-
componentFactory = this._componentFactoryResolver.resolveComponentFactory(componentOrFactory);
503+
componentFactory =
504+
this._componentFactoryResolver.resolveComponentFactory(componentOrFactory) !;
504505
}
505506
this._rootComponentTypes.push(componentFactory.componentType);
506507

0 commit comments

Comments
 (0)