fix(core): Update types for TypeScript nullability support (#15472)
This commit is contained in:

committed by
Victor Berchet

parent
331b9f6425
commit
910c0d9ee7
@ -56,7 +56,7 @@ function declareTests({useJit}: {useJit: boolean}) {
|
||||
const template = '<div>{{null}}{{ctxProp}}</div>';
|
||||
TestBed.overrideComponent(MyComp, {set: {template}});
|
||||
const fixture = TestBed.createComponent(MyComp);
|
||||
fixture.componentInstance.ctxProp = null;
|
||||
fixture.componentInstance.ctxProp = null !;
|
||||
|
||||
fixture.detectChanges();
|
||||
expect(fixture.nativeElement).toHaveText('');
|
||||
@ -134,7 +134,7 @@ function declareTests({useJit}: {useJit: boolean}) {
|
||||
expect(getDOM().getAttribute(fixture.debugElement.children[0].nativeElement, 'foo'))
|
||||
.toEqual('bar');
|
||||
|
||||
fixture.componentInstance.ctxProp = null;
|
||||
fixture.componentInstance.ctxProp = null !;
|
||||
fixture.detectChanges();
|
||||
expect(getDOM().hasAttribute(fixture.debugElement.children[0].nativeElement, 'foo'))
|
||||
.toBeFalsy();
|
||||
@ -151,7 +151,7 @@ function declareTests({useJit}: {useJit: boolean}) {
|
||||
expect(getDOM().getStyle(fixture.debugElement.children[0].nativeElement, 'height'))
|
||||
.toEqual('10px');
|
||||
|
||||
fixture.componentInstance.ctxProp = null;
|
||||
fixture.componentInstance.ctxProp = null !;
|
||||
fixture.detectChanges();
|
||||
expect(getDOM().getStyle(fixture.debugElement.children[0].nativeElement, 'height'))
|
||||
.toEqual('');
|
||||
@ -264,7 +264,7 @@ function declareTests({useJit}: {useJit: boolean}) {
|
||||
fixture.componentInstance.ctxProp = 'a';
|
||||
fixture.detectChanges();
|
||||
|
||||
const dir = fixture.debugElement.children[0].references['dir'];
|
||||
const dir = fixture.debugElement.children[0].references !['dir'];
|
||||
expect(dir.dirProp).toEqual('aa');
|
||||
});
|
||||
});
|
||||
@ -450,7 +450,7 @@ function declareTests({useJit}: {useJit: boolean}) {
|
||||
TestBed.overrideComponent(MyComp, {set: {template}});
|
||||
const fixture = TestBed.createComponent(MyComp);
|
||||
|
||||
expect(fixture.debugElement.children[0].children[0].references['alice'])
|
||||
expect(fixture.debugElement.children[0].children[0].references !['alice'])
|
||||
.toBeAnInstanceOf(ChildComp);
|
||||
});
|
||||
|
||||
@ -460,7 +460,7 @@ function declareTests({useJit}: {useJit: boolean}) {
|
||||
TestBed.overrideComponent(MyComp, {set: {template}});
|
||||
const fixture = TestBed.createComponent(MyComp);
|
||||
|
||||
expect(fixture.debugElement.children[0].children[0].references['localdir'])
|
||||
expect(fixture.debugElement.children[0].children[0].references !['localdir'])
|
||||
.toBeAnInstanceOf(ExportDir);
|
||||
});
|
||||
|
||||
@ -486,8 +486,8 @@ function declareTests({useJit}: {useJit: boolean}) {
|
||||
|
||||
const pEl = fixture.debugElement.children[0];
|
||||
|
||||
const alice = pEl.children[0].references['alice'];
|
||||
const bob = pEl.children[1].references['bob'];
|
||||
const alice = pEl.children[0].references !['alice'];
|
||||
const bob = pEl.children[1].references !['bob'];
|
||||
expect(alice).toBeAnInstanceOf(ChildComp);
|
||||
expect(bob).toBeAnInstanceOf(ChildComp);
|
||||
expect(alice).not.toBe(bob);
|
||||
@ -499,7 +499,8 @@ function declareTests({useJit}: {useJit: boolean}) {
|
||||
TestBed.overrideComponent(MyComp, {set: {template}});
|
||||
const fixture = TestBed.createComponent(MyComp);
|
||||
|
||||
expect(fixture.debugElement.children[0].references['alice']).toBeAnInstanceOf(ChildComp);
|
||||
expect(fixture.debugElement.children[0].references !['alice'])
|
||||
.toBeAnInstanceOf(ChildComp);
|
||||
});
|
||||
|
||||
it('should assign the element instance to a user-defined variable', () => {
|
||||
@ -508,7 +509,7 @@ function declareTests({useJit}: {useJit: boolean}) {
|
||||
TestBed.overrideComponent(MyComp, {set: {template}});
|
||||
const fixture = TestBed.createComponent(MyComp);
|
||||
|
||||
const value = fixture.debugElement.children[0].children[0].references['alice'];
|
||||
const value = fixture.debugElement.children[0].children[0].references !['alice'];
|
||||
expect(value).not.toBe(null);
|
||||
expect(value.tagName.toLowerCase()).toEqual('div');
|
||||
});
|
||||
@ -520,7 +521,7 @@ function declareTests({useJit}: {useJit: boolean}) {
|
||||
MyComp, {set: {template: '<ng-template ref-alice></ng-template>'}})
|
||||
.createComponent(MyComp);
|
||||
|
||||
const value = fixture.debugElement.childNodes[0].references['alice'];
|
||||
const value = fixture.debugElement.childNodes[0].references !['alice'];
|
||||
expect(value.createEmbeddedView).toBeTruthy();
|
||||
});
|
||||
|
||||
@ -530,7 +531,7 @@ function declareTests({useJit}: {useJit: boolean}) {
|
||||
TestBed.overrideComponent(MyComp, {set: {template}});
|
||||
const fixture = TestBed.createComponent(MyComp);
|
||||
|
||||
expect(fixture.debugElement.children[0].children[0].references['superAlice'])
|
||||
expect(fixture.debugElement.children[0].children[0].references !['superAlice'])
|
||||
.toBeAnInstanceOf(ChildComp);
|
||||
});
|
||||
});
|
||||
@ -559,7 +560,7 @@ function declareTests({useJit}: {useJit: boolean}) {
|
||||
TestBed.overrideComponent(MyComp, {set: {template}});
|
||||
const fixture = TestBed.createComponent(MyComp);
|
||||
|
||||
const cmp = fixture.debugElement.children[0].references['cmp'];
|
||||
const cmp = fixture.debugElement.children[0].references !['cmp'];
|
||||
|
||||
fixture.detectChanges();
|
||||
expect(cmp.numberOfChecks).toEqual(1);
|
||||
@ -580,7 +581,7 @@ function declareTests({useJit}: {useJit: boolean}) {
|
||||
TestBed.overrideComponent(MyComp, {set: {template}});
|
||||
const fixture = TestBed.createComponent(MyComp);
|
||||
|
||||
const cmp = fixture.debugElement.children[0].references['cmp'];
|
||||
const cmp = fixture.debugElement.children[0].references !['cmp'];
|
||||
|
||||
fixture.componentInstance.ctxProp = 'one';
|
||||
fixture.detectChanges();
|
||||
@ -654,7 +655,7 @@ function declareTests({useJit}: {useJit: boolean}) {
|
||||
TestBed.overrideComponent(MyComp, {set: {template}});
|
||||
const fixture = TestBed.createComponent(MyComp);
|
||||
|
||||
const cmp = fixture.debugElement.children[0].references['cmp'];
|
||||
const cmp = fixture.debugElement.children[0].references !['cmp'];
|
||||
|
||||
fixture.componentInstance.ctxProp = 'one';
|
||||
fixture.detectChanges();
|
||||
@ -675,7 +676,8 @@ function declareTests({useJit}: {useJit: boolean}) {
|
||||
|
||||
tick();
|
||||
|
||||
const cmp: PushCmpWithAsyncPipe = fixture.debugElement.children[0].references['cmp'];
|
||||
const cmp: PushCmpWithAsyncPipe =
|
||||
fixture.debugElement.children[0].references !['cmp'];
|
||||
fixture.detectChanges();
|
||||
expect(cmp.numberOfChecks).toEqual(1);
|
||||
|
||||
@ -707,7 +709,7 @@ function declareTests({useJit}: {useJit: boolean}) {
|
||||
const fixture = TestBed.createComponent(MyComp);
|
||||
|
||||
const childComponent =
|
||||
fixture.debugElement.children[0].children[0].children[0].references['child'];
|
||||
fixture.debugElement.children[0].children[0].children[0].references !['child'];
|
||||
expect(childComponent.myHost).toBeAnInstanceOf(SomeDirective);
|
||||
});
|
||||
|
||||
@ -729,7 +731,7 @@ function declareTests({useJit}: {useJit: boolean}) {
|
||||
|
||||
const tc = fixture.debugElement.children[0].children[0].children[0];
|
||||
|
||||
const childComponent = tc.references['child'];
|
||||
const childComponent = tc.references !['child'];
|
||||
expect(childComponent.myHost).toBeAnInstanceOf(SomeDirective);
|
||||
});
|
||||
|
||||
@ -1232,7 +1234,7 @@ function declareTests({useJit}: {useJit: boolean}) {
|
||||
TestBed.overrideComponent(MyComp, {set: {template}});
|
||||
const fixture = TestBed.createComponent(MyComp);
|
||||
|
||||
const comp = fixture.debugElement.children[0].children[0].references['consuming'];
|
||||
const comp = fixture.debugElement.children[0].children[0].references !['consuming'];
|
||||
expect(comp.injectable).toBeAnInstanceOf(InjectableService);
|
||||
});
|
||||
|
||||
@ -1248,7 +1250,7 @@ function declareTests({useJit}: {useJit: boolean}) {
|
||||
TestBed.overrideComponent(DirectiveProvidingInjectableInView, {set: {template}});
|
||||
const fixture = TestBed.createComponent(DirectiveProvidingInjectableInView);
|
||||
|
||||
const comp = fixture.debugElement.children[0].references['consuming'];
|
||||
const comp = fixture.debugElement.children[0].references !['consuming'];
|
||||
expect(comp.injectable).toBeAnInstanceOf(InjectableService);
|
||||
});
|
||||
|
||||
@ -1276,7 +1278,7 @@ function declareTests({useJit}: {useJit: boolean}) {
|
||||
});
|
||||
const fixture = TestBed.createComponent(MyComp);
|
||||
|
||||
const comp = fixture.debugElement.children[0].children[0].references['dir'];
|
||||
const comp = fixture.debugElement.children[0].children[0].references !['dir'];
|
||||
expect(comp.directive.injectable).toBeAnInstanceOf(InjectableService);
|
||||
});
|
||||
|
||||
@ -1326,7 +1328,7 @@ function declareTests({useJit}: {useJit: boolean}) {
|
||||
TestBed.overrideComponent(MyComp, {set: {template}});
|
||||
const fixture = TestBed.createComponent(MyComp);
|
||||
|
||||
const providing = fixture.debugElement.children[0].references['providing'];
|
||||
const providing = fixture.debugElement.children[0].references !['providing'];
|
||||
expect(providing.created).toBe(false);
|
||||
|
||||
fixture.componentInstance.ctxBoolProp = true;
|
||||
@ -1363,7 +1365,7 @@ function declareTests({useJit}: {useJit: boolean}) {
|
||||
});
|
||||
|
||||
it('should use a default element name for components without selectors', () => {
|
||||
let noSelectorComponentFactory: ComponentFactory<SomeComponent>;
|
||||
let noSelectorComponentFactory: ComponentFactory<SomeComponent> = undefined !;
|
||||
|
||||
@Component({template: '----'})
|
||||
class NoSelectorComponent {
|
||||
@ -1374,7 +1376,7 @@ function declareTests({useJit}: {useJit: boolean}) {
|
||||
constructor(componentFactoryResolver: ComponentFactoryResolver) {
|
||||
// grab its own component factory
|
||||
noSelectorComponentFactory =
|
||||
componentFactoryResolver.resolveComponentFactory(NoSelectorComponent);
|
||||
componentFactoryResolver.resolveComponentFactory(NoSelectorComponent) !;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1843,7 +1845,8 @@ class DynamicViewport {
|
||||
|
||||
this.injector = ReflectiveInjector.resolveAndCreate(
|
||||
[{provide: MyService, useValue: myService}], vc.injector);
|
||||
this.componentFactory = componentFactoryResolver.resolveComponentFactory(ChildCompUsingService);
|
||||
this.componentFactory =
|
||||
componentFactoryResolver.resolveComponentFactory(ChildCompUsingService) !;
|
||||
}
|
||||
|
||||
create() { this.vc.createComponent(this.componentFactory, this.vc.length, this.injector); }
|
||||
@ -1970,7 +1973,7 @@ class MyComp {
|
||||
})
|
||||
class ChildComp {
|
||||
ctxProp: string;
|
||||
dirProp: string;
|
||||
dirProp: string|null;
|
||||
constructor(service: MyService) {
|
||||
this.ctxProp = service.greeting;
|
||||
this.dirProp = null;
|
||||
@ -2006,7 +2009,7 @@ class CompWithHost {
|
||||
@Component({selector: '[child-cmp2]', viewProviders: [MyService]})
|
||||
class ChildComp2 {
|
||||
ctxProp: string;
|
||||
dirProp: string;
|
||||
dirProp: string|null;
|
||||
constructor(service: MyService) {
|
||||
this.ctxProp = service.greeting;
|
||||
this.dirProp = null;
|
||||
@ -2277,7 +2280,7 @@ class EventBus {
|
||||
|
||||
@Directive({
|
||||
selector: 'grand-parent-providing-event-bus',
|
||||
providers: [{provide: EventBus, useValue: new EventBus(null, 'grandparent')}]
|
||||
providers: [{provide: EventBus, useValue: new EventBus(null !, 'grandparent')}]
|
||||
})
|
||||
class GrandParentProvidingEventBus {
|
||||
bus: EventBus;
|
||||
@ -2313,7 +2316,7 @@ class ChildConsumingEventBus {
|
||||
|
||||
@Directive({selector: '[someImpvp]', inputs: ['someImpvp']})
|
||||
class SomeImperativeViewport {
|
||||
view: EmbeddedViewRef<Object>;
|
||||
view: EmbeddedViewRef<Object>|null;
|
||||
anchor: any;
|
||||
constructor(
|
||||
public vc: ViewContainerRef, public templateRef: TemplateRef<Object>,
|
||||
|
Reference in New Issue
Block a user