fix(docs-infra): fix parameters with @Optional() decorator do not match declared, optional type (#35150)
PR Close #35150
This commit is contained in:
parent
5b80e944be
commit
79742a397f
|
@ -23,7 +23,7 @@ export class HeroContactComponent {
|
||||||
|
|
||||||
@Host() // limit search for logger; hides the application-wide logger
|
@Host() // limit search for logger; hides the application-wide logger
|
||||||
@Optional() // ok if the logger doesn't exist
|
@Optional() // ok if the logger doesn't exist
|
||||||
private loggerService: LoggerService
|
private loggerService?: LoggerService
|
||||||
// #enddocregion ctor-params
|
// #enddocregion ctor-params
|
||||||
) {
|
) {
|
||||||
if (loggerService) {
|
if (loggerService) {
|
||||||
|
|
|
@ -52,7 +52,7 @@ const templateC = `
|
||||||
export class CarolComponent {
|
export class CarolComponent {
|
||||||
name = 'Carol';
|
name = 'Carol';
|
||||||
// #docregion carol-ctor
|
// #docregion carol-ctor
|
||||||
constructor( @Optional() public parent: Parent ) { }
|
constructor( @Optional() public parent?: Parent ) { }
|
||||||
// #enddocregion carol-ctor
|
// #enddocregion carol-ctor
|
||||||
}
|
}
|
||||||
// #enddocregion carol-class
|
// #enddocregion carol-class
|
||||||
|
@ -64,7 +64,7 @@ export class CarolComponent {
|
||||||
})
|
})
|
||||||
export class ChrisComponent {
|
export class ChrisComponent {
|
||||||
name = 'Chris';
|
name = 'Chris';
|
||||||
constructor( @Optional() public parent: Parent ) { }
|
constructor( @Optional() public parent?: Parent ) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
////// Craig ///////////
|
////// Craig ///////////
|
||||||
|
@ -81,7 +81,7 @@ export class ChrisComponent {
|
||||||
</div>`
|
</div>`
|
||||||
})
|
})
|
||||||
export class CraigComponent {
|
export class CraigComponent {
|
||||||
constructor( @Optional() public alex: Base ) { }
|
constructor( @Optional() public alex?: Base ) { }
|
||||||
}
|
}
|
||||||
// #enddocregion craig
|
// #enddocregion craig
|
||||||
|
|
||||||
|
@ -105,7 +105,7 @@ const templateB = `
|
||||||
export class BarryComponent implements Parent {
|
export class BarryComponent implements Parent {
|
||||||
name = 'Barry';
|
name = 'Barry';
|
||||||
// #docregion barry-ctor
|
// #docregion barry-ctor
|
||||||
constructor( @SkipSelf() @Optional() public parent: Parent ) { }
|
constructor( @SkipSelf() @Optional() public parent?: Parent ) { }
|
||||||
// #enddocregion barry-ctor
|
// #enddocregion barry-ctor
|
||||||
}
|
}
|
||||||
// #enddocregion barry
|
// #enddocregion barry
|
||||||
|
@ -117,7 +117,7 @@ export class BarryComponent implements Parent {
|
||||||
})
|
})
|
||||||
export class BobComponent implements Parent {
|
export class BobComponent implements Parent {
|
||||||
name = 'Bob';
|
name = 'Bob';
|
||||||
constructor( @SkipSelf() @Optional() public parent: Parent ) { }
|
constructor( @SkipSelf() @Optional() public parent?: Parent ) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
|
@ -129,7 +129,7 @@ export class BobComponent implements Parent {
|
||||||
})
|
})
|
||||||
export class BethComponent implements Parent {
|
export class BethComponent implements Parent {
|
||||||
name = 'Beth';
|
name = 'Beth';
|
||||||
constructor( @SkipSelf() @Optional() public parent: Parent ) { }
|
constructor( @SkipSelf() @Optional() public parent?: Parent ) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
///////// A - Grandparent //////
|
///////// A - Grandparent //////
|
||||||
|
@ -200,7 +200,7 @@ export class AliceComponent implements Parent
|
||||||
</div>`
|
</div>`
|
||||||
})
|
})
|
||||||
export class CathyComponent {
|
export class CathyComponent {
|
||||||
constructor( @Optional() public alex: AlexComponent ) { }
|
constructor( @Optional() public alex?: AlexComponent ) { }
|
||||||
}
|
}
|
||||||
// #enddocregion cathy
|
// #enddocregion cathy
|
||||||
|
|
||||||
|
|
|
@ -247,7 +247,7 @@ let some_message = 'Hello from the injected logger';
|
||||||
export class Provider10Component implements OnInit {
|
export class Provider10Component implements OnInit {
|
||||||
log: string;
|
log: string;
|
||||||
// #docregion provider-10-ctor
|
// #docregion provider-10-ctor
|
||||||
constructor(@Optional() private logger: Logger) {
|
constructor(@Optional() private logger?: Logger) {
|
||||||
if (this.logger) {
|
if (this.logger) {
|
||||||
this.logger.log(some_message);
|
this.logger.log(some_message);
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ import { UserServiceConfig } from './user.service';
|
||||||
})
|
})
|
||||||
export class GreetingModule {
|
export class GreetingModule {
|
||||||
// #docregion ctor
|
// #docregion ctor
|
||||||
constructor (@Optional() @SkipSelf() parentModule: GreetingModule) {
|
constructor (@Optional() @SkipSelf() parentModule?: GreetingModule) {
|
||||||
if (parentModule) {
|
if (parentModule) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
'GreetingModule is already loaded. Import it in the AppModule only');
|
'GreetingModule is already loaded. Import it in the AppModule only');
|
||||||
|
|
|
@ -15,7 +15,7 @@ export class UserService {
|
||||||
private _userName = 'Sherlock Holmes';
|
private _userName = 'Sherlock Holmes';
|
||||||
|
|
||||||
// #docregion ctor
|
// #docregion ctor
|
||||||
constructor(@Optional() config: UserServiceConfig) {
|
constructor(@Optional() config?: UserServiceConfig) {
|
||||||
if (config) { this._userName = config.userName; }
|
if (config) { this._userName = config.userName; }
|
||||||
}
|
}
|
||||||
// #enddocregion ctor
|
// #enddocregion ctor
|
||||||
|
|
|
@ -24,7 +24,7 @@ export class ChildComponent {
|
||||||
// inspector is in the content.
|
// 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
|
// Comment out the above constructor and alternately
|
||||||
// uncomment the two following constructors to see the
|
// uncomment the two following constructors to see the
|
||||||
|
@ -32,11 +32,11 @@ export class ChildComponent {
|
||||||
|
|
||||||
// constructor(
|
// constructor(
|
||||||
// @Host() public animal : AnimalService,
|
// @Host() public animal : AnimalService,
|
||||||
// @Host() @Optional() public flower : FlowerService) { }
|
// @Host() @Optional() public flower ?: FlowerService) { }
|
||||||
|
|
||||||
// constructor(
|
// constructor(
|
||||||
// @SkipSelf() @Host() public animal : AnimalService,
|
// @SkipSelf() @Host() public animal : AnimalService,
|
||||||
// @SkipSelf() @Host() @Optional() public flower : FlowerService) { }
|
// @SkipSelf() @Host() @Optional() public flower ?: FlowerService) { }
|
||||||
|
|
||||||
// #docregion provide-animal-service
|
// #docregion provide-animal-service
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ import { FlowerService } from '../flower.service';
|
||||||
})
|
})
|
||||||
export class HostComponent {
|
export class HostComponent {
|
||||||
// use @Host() in the constructor when injecting the service
|
// use @Host() in the constructor when injecting the service
|
||||||
constructor(@Host() @Optional() public flower: FlowerService) { }
|
constructor(@Host() @Optional() public flower?: FlowerService) { }
|
||||||
|
|
||||||
}
|
}
|
||||||
// #enddocregion host-component
|
// #enddocregion host-component
|
||||||
|
|
|
@ -9,7 +9,7 @@ import { OptionalService } from '../optional.service';
|
||||||
|
|
||||||
// #docregion optional-component
|
// #docregion optional-component
|
||||||
export class OptionalComponent {
|
export class OptionalComponent {
|
||||||
constructor(@Optional() public optional: OptionalService) {}
|
constructor(@Optional() public optional?: OptionalService) {}
|
||||||
}
|
}
|
||||||
// #enddocregion optional-component
|
// #enddocregion optional-component
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ import { LeafService } from '../leaf.service';
|
||||||
styleUrls: ['./self-no-data.component.css']
|
styleUrls: ['./self-no-data.component.css']
|
||||||
})
|
})
|
||||||
export class SelfNoDataComponent {
|
export class SelfNoDataComponent {
|
||||||
constructor(@Self() @Optional() public leaf: LeafService) { }
|
constructor(@Self() @Optional() public leaf?: LeafService) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
// #enddocregion self-no-data-component
|
// #enddocregion self-no-data-component
|
||||||
|
|
|
@ -15,7 +15,7 @@ import { throwIfAlreadyLoaded } from './module-import-guard';
|
||||||
providers: [LoggerService]
|
providers: [LoggerService]
|
||||||
})
|
})
|
||||||
export class CoreModule {
|
export class CoreModule {
|
||||||
constructor( @Optional() @SkipSelf() parentModule: CoreModule) {
|
constructor( @Optional() @SkipSelf() parentModule?: CoreModule) {
|
||||||
throwIfAlreadyLoaded(parentModule, 'CoreModule');
|
throwIfAlreadyLoaded(parentModule, 'CoreModule');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -248,7 +248,7 @@ export class TestViewProvidersComponent {
|
||||||
export class ExternalTemplateComponent implements OnInit {
|
export class ExternalTemplateComponent implements OnInit {
|
||||||
serviceValue: string;
|
serviceValue: string;
|
||||||
|
|
||||||
constructor(@Optional() private service: ValueService) { }
|
constructor(@Optional() private service?: ValueService) { }
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
if (this.service) { this.serviceValue = this.service.getValue(); }
|
if (this.service) { this.serviceValue = this.service.getValue(); }
|
||||||
|
|
|
@ -21,7 +21,7 @@ export class HeroService {
|
||||||
constructor(
|
constructor(
|
||||||
private http: HttpClient,
|
private http: HttpClient,
|
||||||
private messageService: MessageService,
|
private messageService: MessageService,
|
||||||
@Optional() @Inject(APP_BASE_HREF) origin: string) {
|
@Optional() @Inject(APP_BASE_HREF) origin?: string) {
|
||||||
this.heroesUrl = `${origin}${this.heroesUrl}`;
|
this.heroesUrl = `${origin}${this.heroesUrl}`;
|
||||||
}
|
}
|
||||||
// #enddocregion ctor
|
// #enddocregion ctor
|
||||||
|
|
|
@ -320,7 +320,7 @@ Use `@SkipSelf()` with `@Optional()` to prevent an error if the value is `null`.
|
||||||
|
|
||||||
``` ts
|
``` ts
|
||||||
class Person {
|
class Person {
|
||||||
constructor(@Optional() @SkipSelf() parent: Person) {}
|
constructor(@Optional() @SkipSelf() parent?: Person) {}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -214,7 +214,7 @@ import {REQUEST} from '@nguniversal/express-engine/tokens';
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class UniversalInterceptor implements HttpInterceptor {
|
export class UniversalInterceptor implements HttpInterceptor {
|
||||||
|
|
||||||
constructor(@Optional() @Inject(REQUEST) protected request: Request) {}
|
constructor(@Optional() @Inject(REQUEST) protected request?: Request) {}
|
||||||
|
|
||||||
intercept(req: HttpRequest<any>, next: HttpHandler) {
|
intercept(req: HttpRequest<any>, next: HttpHandler) {
|
||||||
let serverReq: HttpRequest<any> = req;
|
let serverReq: HttpRequest<any> = req;
|
||||||
|
|
Loading…
Reference in New Issue