fix(core): Update types for TypeScript nullability support (#15472)

This commit is contained in:
Miško Hevery
2017-03-29 09:34:45 -07:00
committed by Victor Berchet
parent 331b9f6425
commit 910c0d9ee7
84 changed files with 1287 additions and 1260 deletions

View File

@ -115,7 +115,7 @@ export abstract class ReflectiveInjector implements Injector {
* because it needs to resolve the passed-in providers first.
* See {@link Injector#resolve} and {@link Injector#fromResolvedProviders}.
*/
static resolveAndCreate(providers: Provider[], parent: Injector = null): ReflectiveInjector {
static resolveAndCreate(providers: Provider[], parent?: Injector): ReflectiveInjector {
const ResolvedReflectiveProviders = ReflectiveInjector.resolve(providers);
return ReflectiveInjector.fromResolvedProviders(ResolvedReflectiveProviders, parent);
}
@ -143,7 +143,7 @@ export abstract class ReflectiveInjector implements Injector {
* ```
* @experimental
*/
static fromResolvedProviders(providers: ResolvedReflectiveProvider[], parent: Injector = null):
static fromResolvedProviders(providers: ResolvedReflectiveProvider[], parent?: Injector):
ReflectiveInjector {
return new ReflectiveInjector_(providers, parent);
}
@ -163,7 +163,7 @@ export abstract class ReflectiveInjector implements Injector {
* expect(child.parent).toBe(parent);
* ```
*/
abstract get parent(): Injector;
abstract get parent(): Injector|null;
/**
* Resolves an array of providers and creates a child injector from those providers.
@ -282,16 +282,16 @@ export class ReflectiveInjector_ implements ReflectiveInjector {
/** @internal */
public _providers: ResolvedReflectiveProvider[];
/** @internal */
public _parent: Injector;
public _parent: Injector|null;
keyIds: number[];
objs: any[];
/**
* Private
*/
constructor(_providers: ResolvedReflectiveProvider[], _parent: Injector = null) {
constructor(_providers: ResolvedReflectiveProvider[], _parent?: Injector) {
this._providers = _providers;
this._parent = _parent;
this._parent = _parent || null;
const len = _providers.length;
@ -308,7 +308,7 @@ export class ReflectiveInjector_ implements ReflectiveInjector {
return this._getByKey(ReflectiveKey.get(token), null, notFoundValue);
}
get parent(): Injector { return this._parent; }
get parent(): Injector|null { return this._parent; }
resolveAndCreateChild(providers: Provider[]): ReflectiveInjector {
const ResolvedReflectiveProviders = ReflectiveInjector.resolve(providers);
@ -388,7 +388,7 @@ export class ReflectiveInjector_ implements ReflectiveInjector {
return this._getByKey(dep.key, dep.visibility, dep.optional ? null : THROW_IF_NOT_FOUND);
}
private _getByKey(key: ReflectiveKey, visibility: Self|SkipSelf, notFoundValue: any): any {
private _getByKey(key: ReflectiveKey, visibility: Self|SkipSelf|null, notFoundValue: any): any {
if (key === INJECTOR_KEY) {
return this;
}
@ -431,8 +431,8 @@ export class ReflectiveInjector_ implements ReflectiveInjector {
}
/** @internal */
_getByKeyDefault(key: ReflectiveKey, notFoundValue: any, visibility: Self|SkipSelf): any {
let inj: Injector;
_getByKeyDefault(key: ReflectiveKey, notFoundValue: any, visibility: Self|SkipSelf|null): any {
let inj: Injector|null;
if (visibility instanceof SkipSelf) {
inj = this._parent;

View File

@ -64,7 +64,7 @@ export class KeyRegistry {
if (token instanceof ReflectiveKey) return token;
if (this._allKeys.has(token)) {
return this._allKeys.get(token);
return this._allKeys.get(token) !;
}
const newKey = new ReflectiveKey(token, ReflectiveKey.numberOfKeys);

View File

@ -26,7 +26,7 @@ interface NormalizedProvider extends TypeProvider, ValueProvider, ClassProvider,
*/
export class ReflectiveDependency {
constructor(
public key: ReflectiveKey, public optional: boolean, public visibility: Self|SkipSelf) {}
public key: ReflectiveKey, public optional: boolean, public visibility: Self|SkipSelf|null) {}
static fromKey(key: ReflectiveKey): ReflectiveDependency {
return new ReflectiveDependency(key, false, null);
@ -128,7 +128,8 @@ function resolveReflectiveFactory(provider: NormalizedProvider): ResolvedReflect
*/
function resolveReflectiveProvider(provider: NormalizedProvider): ResolvedReflectiveProvider {
return new ResolvedReflectiveProvider_(
ReflectiveKey.get(provider.provide), [resolveReflectiveFactory(provider)], provider.multi);
ReflectiveKey.get(provider.provide), [resolveReflectiveFactory(provider)],
provider.multi || false);
}
/**
@ -198,7 +199,7 @@ function _normalizeProviders(providers: Provider[], res: Provider[]): Provider[]
}
export function constructDependencies(
typeOrFunc: any, dependencies: any[]): ReflectiveDependency[] {
typeOrFunc: any, dependencies?: any[]): ReflectiveDependency[] {
if (!dependencies) {
return _dependenciesFor(typeOrFunc);
} else {
@ -230,7 +231,7 @@ function _extractToken(
}
}
let visibility: Self|SkipSelf = null;
let visibility: Self|SkipSelf|null = null;
for (let i = 0; i < metadata.length; ++i) {
const paramMetadata = metadata[i];
@ -261,6 +262,6 @@ function _extractToken(
}
function _createDependency(
token: any, optional: boolean, visibility: Self | SkipSelf): ReflectiveDependency {
token: any, optional: boolean, visibility: Self | SkipSelf | null): ReflectiveDependency {
return new ReflectiveDependency(ReflectiveKey.get(token), optional, visibility);
}