From cca26166376d4920f5905b168e70ea2e8d70da77 Mon Sep 17 00:00:00 2001 From: Kristiyan Kostadinov Date: Tue, 3 Dec 2019 11:59:46 +0100 Subject: [PATCH] refactor(common): add defaults to new generic parameters (#34206) This is a follow-up to #33997 where some new generic parameters were added without defaults which is technically a breaking change. These changes add the defaults. PR Close #34206 --- packages/common/src/directives/ng_for_of.ts | 4 ++-- packages/common/src/directives/ng_if.ts | 4 ++-- .../compiler-cli/test/ngtsc/template_typecheck_spec.ts | 8 ++++---- tools/public_api_guard/common/common.d.ts | 8 ++++---- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/packages/common/src/directives/ng_for_of.ts b/packages/common/src/directives/ng_for_of.ts index c3d8e1c192..f490432c4c 100644 --- a/packages/common/src/directives/ng_for_of.ts +++ b/packages/common/src/directives/ng_for_of.ts @@ -11,7 +11,7 @@ import {Directive, DoCheck, EmbeddedViewRef, Input, IterableChangeRecord, Iterab /** * @publicApi */ -export class NgForOfContext> { +export class NgForOfContext = NgIterable> { constructor(public $implicit: T, public ngForOf: U, public index: number, public count: number) {} get first(): boolean { return this.index === 0; } @@ -121,7 +121,7 @@ export class NgForOfContext> { * @publicApi */ @Directive({selector: '[ngFor][ngForOf]'}) -export class NgForOf> implements DoCheck { +export class NgForOf = NgIterable> implements DoCheck { /** * The value of the iterable expression, which can be used as a * [template input variable](guide/structural-directives#template-input-variable). diff --git a/packages/common/src/directives/ng_if.ts b/packages/common/src/directives/ng_if.ts index 3520fd0ead..98fc3c328e 100644 --- a/packages/common/src/directives/ng_if.ts +++ b/packages/common/src/directives/ng_if.ts @@ -149,7 +149,7 @@ import {Directive, EmbeddedViewRef, Input, TemplateRef, ViewContainerRef, ɵstri * @publicApi */ @Directive({selector: '[ngIf]'}) -export class NgIf { +export class NgIf { private _context: NgIfContext = new NgIfContext(); private _thenTemplateRef: TemplateRef>|null = null; private _elseTemplateRef: TemplateRef>|null = null; @@ -238,7 +238,7 @@ export class NgIf { /** * @publicApi */ -export class NgIfContext { +export class NgIfContext { public $implicit: T = null !; public ngIf: T = null !; } diff --git a/packages/compiler-cli/test/ngtsc/template_typecheck_spec.ts b/packages/compiler-cli/test/ngtsc/template_typecheck_spec.ts index 16c1f76ceb..39b7b48458 100644 --- a/packages/compiler-cli/test/ngtsc/template_typecheck_spec.ts +++ b/packages/compiler-cli/test/ngtsc/template_typecheck_spec.ts @@ -26,7 +26,7 @@ runInEachFileSystem(() => { env.write('node_modules/@angular/common/index.d.ts', ` import * as i0 from '@angular/core'; -export declare class NgForOfContext> { +export declare class NgForOfContext = i0.NgIterable> { $implicit: T; count: number; readonly even: boolean; @@ -54,7 +54,7 @@ export declare class SlicePipe { static ɵpipe: i0.ɵPipeDefWithMeta; } -export declare class NgForOf> implements DoCheck { +export declare class NgForOf = i0.NgIterable> implements DoCheck { ngForOf: (U & i0.NgIterable) | undefined | null; ngForTemplate: TemplateRef>; ngForTrackBy: TrackByFunction; @@ -64,7 +64,7 @@ export declare class NgForOf> implements DoCheck { static ɵdir: i0.ɵɵDirectiveDefWithMeta, '[ngFor][ngForOf]', never, {'ngForOf': 'ngForOf'}, {}, never>; } -export declare class NgIf { +export declare class NgIf { ngIf: T; ngIfElse: TemplateRef> | null; ngIfThen: TemplateRef> | null; @@ -74,7 +74,7 @@ export declare class NgIf { static ɵdir: i0.ɵɵDirectiveDefWithMeta, '[ngIf]', never, {'ngIf': 'ngIf'}, {}, never>; } -export declare class NgIfContext { +export declare class NgIfContext { $implicit: T; ngIf: T; } diff --git a/tools/public_api_guard/common/common.d.ts b/tools/public_api_guard/common/common.d.ts index 2b0ccd9f54..8abc8bf99b 100644 --- a/tools/public_api_guard/common/common.d.ts +++ b/tools/public_api_guard/common/common.d.ts @@ -216,7 +216,7 @@ export declare class NgComponentOutlet implements OnChanges, OnDestroy { ngOnDestroy(): void; } -export declare class NgForOf> implements DoCheck { +export declare class NgForOf = NgIterable> implements DoCheck { ngForOf: (U & NgIterable) | undefined | null; ngForTemplate: TemplateRef>; ngForTrackBy: TrackByFunction; @@ -225,7 +225,7 @@ export declare class NgForOf> implements DoCheck { static ngTemplateContextGuard>(dir: NgForOf, ctx: any): ctx is NgForOfContext; } -export declare class NgForOfContext> { +export declare class NgForOfContext = NgIterable> { $implicit: T; count: number; readonly even: boolean; @@ -237,7 +237,7 @@ export declare class NgForOfContext> { constructor($implicit: T, ngForOf: U, index: number, count: number); } -export declare class NgIf { +export declare class NgIf { ngIf: T; ngIfElse: TemplateRef> | null; ngIfThen: TemplateRef> | null; @@ -246,7 +246,7 @@ export declare class NgIf { static ngTemplateContextGuard(dir: NgIf, ctx: any): ctx is NgIfContext; } -export declare class NgIfContext { +export declare class NgIfContext { $implicit: T; ngIf: T; }