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
|
||||
@Optional() // ok if the logger doesn't exist
|
||||
private loggerService: LoggerService
|
||||
private loggerService?: LoggerService
|
||||
// #enddocregion ctor-params
|
||||
) {
|
||||
if (loggerService) {
|
||||
|
|
|
@ -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 {
|
|||
</div>`
|
||||
})
|
||||
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
|
|||
</div>`
|
||||
})
|
||||
export class CathyComponent {
|
||||
constructor( @Optional() public alex: AlexComponent ) { }
|
||||
constructor( @Optional() public alex?: AlexComponent ) { }
|
||||
}
|
||||
// #enddocregion cathy
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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');
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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(); }
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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) {}
|
||||
}
|
||||
```
|
||||
|
||||
|
|
|
@ -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<any>, next: HttpHandler) {
|
||||
let serverReq: HttpRequest<any> = req;
|
||||
|
|
Loading…
Reference in New Issue