refactor(core): ensure compatibility with typescript strict flag (#30993)

As part of FW-1265, the `@angular/core` package is made compatible
with the TypeScript `--strict` flag. This already unveiled a few bugs,
so the strictness flag seems to help with increasing the overall code health.

Read more about the strict flag [here](https://www.typescriptlang.org/docs/handbook/compiler-options.html)

PR Close #30993
This commit is contained in:
Paul Gschwendtner
2019-06-14 09:27:41 +02:00
committed by Miško Hevery
parent 78e7fdd98d
commit 2200884e55
29 changed files with 122 additions and 86 deletions

View File

@ -92,10 +92,10 @@ export interface InjectableType<T> extends Type<T> { ngInjectableDef: ɵɵInject
* Supports @Injectable() in JIT mode for Render2.
*/
function render2CompileInjectable(
injectableType: InjectableType<any>,
options: {providedIn?: Type<any>| 'root' | null} & InjectableProvider): void {
injectableType: Type<any>,
options?: {providedIn?: Type<any>| 'root' | null} & InjectableProvider): void {
if (options && options.providedIn !== undefined && !getInjectableDef(injectableType)) {
injectableType.ngInjectableDef = ɵɵdefineInjectable({
(injectableType as InjectableType<any>).ngInjectableDef = ɵɵdefineInjectable({
token: injectableType,
providedIn: options.providedIn,
factory: convertInjectableProviderToFactory(injectableType, options),

View File

@ -68,8 +68,8 @@ export function setCurrentInjector(injector: Injector | null | undefined): Injec
* 1. `Injector` should not depend on ivy logic.
* 2. To maintain tree shake-ability we don't want to bring in unnecessary code.
*/
let _injectImplementation: (<T>(token: Type<T>| InjectionToken<T>, flags: InjectFlags) => T | null)|
undefined;
let _injectImplementation:
(<T>(token: Type<T>| InjectionToken<T>, flags?: InjectFlags) => T | null)|undefined;
/**
* Sets the current inject implementation.

View File

@ -180,10 +180,11 @@ export function mergeResolvedReflectiveProviders(
return normalizedProvidersMap;
}
function _normalizeProviders(providers: Provider[], res: Provider[]): Provider[] {
function _normalizeProviders(
providers: Provider[], res: NormalizedProvider[]): NormalizedProvider[] {
providers.forEach(b => {
if (b instanceof Type) {
res.push({provide: b, useClass: b});
res.push({ provide: b, useClass: b } as NormalizedProvider);
} else if (b && typeof b == 'object' && (b as any).provide !== undefined) {
res.push(b as NormalizedProvider);