From 79742a397fc60c6d2499d64736bbc476a7e3e6c9 Mon Sep 17 00:00:00 2001 From: Oleg Teterin Date: Wed, 5 Feb 2020 01:34:18 +0300 Subject: [PATCH] fix(docs-infra): fix parameters with @Optional() decorator do not match declared, optional type (#35150) PR Close #35150 --- .../src/app/hero-contact.component.ts | 2 +- .../src/app/parent-finder.component.ts | 14 +++++++------- .../src/app/providers.component.ts | 2 +- .../ngmodules/src/app/greeting/greeting.module.ts | 2 +- .../ngmodules/src/app/greeting/user.service.ts | 2 +- .../src/app/child/child.component.ts | 6 +++--- .../src/app/host/host.component.ts | 2 +- .../src/app/optional/optional.component.ts | 2 +- .../src/app/self-no-data/self-no-data.component.ts | 2 +- .../styleguide/src/04-12/app/core/core.module.ts | 2 +- aio/content/examples/testing/src/app/demo/demo.ts | 2 +- .../examples/universal/src/app/hero.service.ts | 2 +- .../guide/hierarchical-dependency-injection.md | 2 +- aio/content/guide/universal.md | 2 +- 14 files changed, 22 insertions(+), 22 deletions(-) diff --git a/aio/content/examples/dependency-injection-in-action/src/app/hero-contact.component.ts b/aio/content/examples/dependency-injection-in-action/src/app/hero-contact.component.ts index 205e1f9335..5681711831 100644 --- a/aio/content/examples/dependency-injection-in-action/src/app/hero-contact.component.ts +++ b/aio/content/examples/dependency-injection-in-action/src/app/hero-contact.component.ts @@ -23,7 +23,7 @@ export class HeroContactComponent { @Host() // limit search for logger; hides the application-wide logger @Optional() // ok if the logger doesn't exist - private loggerService: LoggerService + private loggerService?: LoggerService // #enddocregion ctor-params ) { if (loggerService) { diff --git a/aio/content/examples/dependency-injection-in-action/src/app/parent-finder.component.ts b/aio/content/examples/dependency-injection-in-action/src/app/parent-finder.component.ts index 76d2c1b2b0..513205e1bd 100644 --- a/aio/content/examples/dependency-injection-in-action/src/app/parent-finder.component.ts +++ b/aio/content/examples/dependency-injection-in-action/src/app/parent-finder.component.ts @@ -52,7 +52,7 @@ const templateC = ` export class CarolComponent { name = 'Carol'; // #docregion carol-ctor - constructor( @Optional() public parent: Parent ) { } + constructor( @Optional() public parent?: Parent ) { } // #enddocregion carol-ctor } // #enddocregion carol-class @@ -64,7 +64,7 @@ export class CarolComponent { }) export class ChrisComponent { name = 'Chris'; - constructor( @Optional() public parent: Parent ) { } + constructor( @Optional() public parent?: Parent ) { } } ////// Craig /////////// @@ -81,7 +81,7 @@ export class ChrisComponent { ` }) export class CraigComponent { - constructor( @Optional() public alex: Base ) { } + constructor( @Optional() public alex?: Base ) { } } // #enddocregion craig @@ -105,7 +105,7 @@ const templateB = ` export class BarryComponent implements Parent { name = 'Barry'; // #docregion barry-ctor - constructor( @SkipSelf() @Optional() public parent: Parent ) { } + constructor( @SkipSelf() @Optional() public parent?: Parent ) { } // #enddocregion barry-ctor } // #enddocregion barry @@ -117,7 +117,7 @@ export class BarryComponent implements Parent { }) export class BobComponent implements Parent { name = 'Bob'; - constructor( @SkipSelf() @Optional() public parent: Parent ) { } + constructor( @SkipSelf() @Optional() public parent?: Parent ) { } } @Component({ @@ -129,7 +129,7 @@ export class BobComponent implements Parent { }) export class BethComponent implements Parent { name = 'Beth'; - constructor( @SkipSelf() @Optional() public parent: Parent ) { } + constructor( @SkipSelf() @Optional() public parent?: Parent ) { } } ///////// A - Grandparent ////// @@ -200,7 +200,7 @@ export class AliceComponent implements Parent ` }) export class CathyComponent { - constructor( @Optional() public alex: AlexComponent ) { } + constructor( @Optional() public alex?: AlexComponent ) { } } // #enddocregion cathy diff --git a/aio/content/examples/dependency-injection/src/app/providers.component.ts b/aio/content/examples/dependency-injection/src/app/providers.component.ts index 6b40f04787..6679fe5ec6 100644 --- a/aio/content/examples/dependency-injection/src/app/providers.component.ts +++ b/aio/content/examples/dependency-injection/src/app/providers.component.ts @@ -247,7 +247,7 @@ let some_message = 'Hello from the injected logger'; export class Provider10Component implements OnInit { log: string; // #docregion provider-10-ctor - constructor(@Optional() private logger: Logger) { + constructor(@Optional() private logger?: Logger) { if (this.logger) { this.logger.log(some_message); } diff --git a/aio/content/examples/ngmodules/src/app/greeting/greeting.module.ts b/aio/content/examples/ngmodules/src/app/greeting/greeting.module.ts index a3e8c56384..952c5efcb1 100644 --- a/aio/content/examples/ngmodules/src/app/greeting/greeting.module.ts +++ b/aio/content/examples/ngmodules/src/app/greeting/greeting.module.ts @@ -14,7 +14,7 @@ import { UserServiceConfig } from './user.service'; }) export class GreetingModule { // #docregion ctor - constructor (@Optional() @SkipSelf() parentModule: GreetingModule) { + constructor (@Optional() @SkipSelf() parentModule?: GreetingModule) { if (parentModule) { throw new Error( 'GreetingModule is already loaded. Import it in the AppModule only'); diff --git a/aio/content/examples/ngmodules/src/app/greeting/user.service.ts b/aio/content/examples/ngmodules/src/app/greeting/user.service.ts index 319f4da788..3908e85a3c 100644 --- a/aio/content/examples/ngmodules/src/app/greeting/user.service.ts +++ b/aio/content/examples/ngmodules/src/app/greeting/user.service.ts @@ -15,7 +15,7 @@ export class UserService { private _userName = 'Sherlock Holmes'; // #docregion ctor - constructor(@Optional() config: UserServiceConfig) { + constructor(@Optional() config?: UserServiceConfig) { if (config) { this._userName = config.userName; } } // #enddocregion ctor diff --git a/aio/content/examples/providers-viewproviders/src/app/child/child.component.ts b/aio/content/examples/providers-viewproviders/src/app/child/child.component.ts index 415bdc5506..5cf97644d0 100755 --- a/aio/content/examples/providers-viewproviders/src/app/child/child.component.ts +++ b/aio/content/examples/providers-viewproviders/src/app/child/child.component.ts @@ -24,7 +24,7 @@ export class ChildComponent { // inspector is in the content. - // constructor( public flower: FlowerService, @Optional() @Host() public animal: AnimalService) { } + // constructor( public flower: FlowerService, @Optional() @Host() public animal?: AnimalService) { } // Comment out the above constructor and alternately // uncomment the two following constructors to see the @@ -32,11 +32,11 @@ export class ChildComponent { // constructor( // @Host() public animal : AnimalService, -// @Host() @Optional() public flower : FlowerService) { } +// @Host() @Optional() public flower ?: FlowerService) { } // constructor( // @SkipSelf() @Host() public animal : AnimalService, -// @SkipSelf() @Host() @Optional() public flower : FlowerService) { } +// @SkipSelf() @Host() @Optional() public flower ?: FlowerService) { } // #docregion provide-animal-service } diff --git a/aio/content/examples/resolution-modifiers/src/app/host/host.component.ts b/aio/content/examples/resolution-modifiers/src/app/host/host.component.ts index 7727bcd5a9..4aa09e0ab3 100755 --- a/aio/content/examples/resolution-modifiers/src/app/host/host.component.ts +++ b/aio/content/examples/resolution-modifiers/src/app/host/host.component.ts @@ -11,7 +11,7 @@ import { FlowerService } from '../flower.service'; }) export class HostComponent { // use @Host() in the constructor when injecting the service - constructor(@Host() @Optional() public flower: FlowerService) { } + constructor(@Host() @Optional() public flower?: FlowerService) { } } // #enddocregion host-component diff --git a/aio/content/examples/resolution-modifiers/src/app/optional/optional.component.ts b/aio/content/examples/resolution-modifiers/src/app/optional/optional.component.ts index 5f82713692..a17373507b 100755 --- a/aio/content/examples/resolution-modifiers/src/app/optional/optional.component.ts +++ b/aio/content/examples/resolution-modifiers/src/app/optional/optional.component.ts @@ -9,7 +9,7 @@ import { OptionalService } from '../optional.service'; // #docregion optional-component export class OptionalComponent { - constructor(@Optional() public optional: OptionalService) {} + constructor(@Optional() public optional?: OptionalService) {} } // #enddocregion optional-component diff --git a/aio/content/examples/resolution-modifiers/src/app/self-no-data/self-no-data.component.ts b/aio/content/examples/resolution-modifiers/src/app/self-no-data/self-no-data.component.ts index b4b508655f..bbe877f946 100755 --- a/aio/content/examples/resolution-modifiers/src/app/self-no-data/self-no-data.component.ts +++ b/aio/content/examples/resolution-modifiers/src/app/self-no-data/self-no-data.component.ts @@ -8,7 +8,7 @@ import { LeafService } from '../leaf.service'; styleUrls: ['./self-no-data.component.css'] }) export class SelfNoDataComponent { - constructor(@Self() @Optional() public leaf: LeafService) { } + constructor(@Self() @Optional() public leaf?: LeafService) { } } // #enddocregion self-no-data-component diff --git a/aio/content/examples/styleguide/src/04-12/app/core/core.module.ts b/aio/content/examples/styleguide/src/04-12/app/core/core.module.ts index 069141bf2a..6d2f609cd4 100644 --- a/aio/content/examples/styleguide/src/04-12/app/core/core.module.ts +++ b/aio/content/examples/styleguide/src/04-12/app/core/core.module.ts @@ -15,7 +15,7 @@ import { throwIfAlreadyLoaded } from './module-import-guard'; providers: [LoggerService] }) export class CoreModule { - constructor( @Optional() @SkipSelf() parentModule: CoreModule) { + constructor( @Optional() @SkipSelf() parentModule?: CoreModule) { throwIfAlreadyLoaded(parentModule, 'CoreModule'); } } diff --git a/aio/content/examples/testing/src/app/demo/demo.ts b/aio/content/examples/testing/src/app/demo/demo.ts index bbf1d8a799..80ece9410e 100644 --- a/aio/content/examples/testing/src/app/demo/demo.ts +++ b/aio/content/examples/testing/src/app/demo/demo.ts @@ -248,7 +248,7 @@ export class TestViewProvidersComponent { export class ExternalTemplateComponent implements OnInit { serviceValue: string; - constructor(@Optional() private service: ValueService) { } + constructor(@Optional() private service?: ValueService) { } ngOnInit() { if (this.service) { this.serviceValue = this.service.getValue(); } diff --git a/aio/content/examples/universal/src/app/hero.service.ts b/aio/content/examples/universal/src/app/hero.service.ts index 5762d04f09..a94634cd55 100644 --- a/aio/content/examples/universal/src/app/hero.service.ts +++ b/aio/content/examples/universal/src/app/hero.service.ts @@ -21,7 +21,7 @@ export class HeroService { constructor( private http: HttpClient, private messageService: MessageService, - @Optional() @Inject(APP_BASE_HREF) origin: string) { + @Optional() @Inject(APP_BASE_HREF) origin?: string) { this.heroesUrl = `${origin}${this.heroesUrl}`; } // #enddocregion ctor diff --git a/aio/content/guide/hierarchical-dependency-injection.md b/aio/content/guide/hierarchical-dependency-injection.md index d7e6a01728..4c80545947 100644 --- a/aio/content/guide/hierarchical-dependency-injection.md +++ b/aio/content/guide/hierarchical-dependency-injection.md @@ -320,7 +320,7 @@ Use `@SkipSelf()` with `@Optional()` to prevent an error if the value is `null`. ``` ts class Person { - constructor(@Optional() @SkipSelf() parent: Person) {} + constructor(@Optional() @SkipSelf() parent?: Person) {} } ``` diff --git a/aio/content/guide/universal.md b/aio/content/guide/universal.md index 2e0a2bf77f..28ec392da4 100644 --- a/aio/content/guide/universal.md +++ b/aio/content/guide/universal.md @@ -214,7 +214,7 @@ import {REQUEST} from '@nguniversal/express-engine/tokens'; @Injectable() export class UniversalInterceptor implements HttpInterceptor { - constructor(@Optional() @Inject(REQUEST) protected request: Request) {} + constructor(@Optional() @Inject(REQUEST) protected request?: Request) {} intercept(req: HttpRequest, next: HttpHandler) { let serverReq: HttpRequest = req;