Recently, I have come into possession of an Angular 4.4 application that utilizes Webpack v3.5 and TypeScript v2.3.3. Struggling to decipher the imported code, I am at a loss understanding its functionality and correctness. To simplify matters for analysis purposes, I have extracted the following snippet:
In my main.ts file, the following declarations are present:
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic;'
return platformBrowserDynamic().bootstrapModule(AppModule).then...;
Essentially, it appears that platformBrowserDynamic is being called as a function in this block. Delving deeper into the @angular/platform-browser-dynamic/platform-browser-dynamic.d.ts file unveils the import statement:
export * from './src/platform-browser-dynamic';
Contained within @angular/platform-browser-dynamic/src/platform-browser-dynamic/platform-browser-dynamic.d.ts are these snippets:
import { PlatformRef, Provider } from '@angular/core';
export declare const platformBrowserDynamic: (extraProviders?: Provider[] | undefined) => PlatformRef;
This indicates that platformBrowserDynamic returns whatever PlatformRef signifies. Moving on to the @angular/core/core.d.ts file, there exists the export:
export * from './public_api';
Exploring further into @angular/core/public_api.d.ts reveals:
export * from './src/core';
The definition of PlatformRef stems from @angular/core/src/core.d.ts where we find:
export { createPlatform, assertPlatform, destroyPlatform, getPlatform, PlatformRef, ApplicationRef, enableProdMode, isDevMode, createPlatformFactory, NgProbeToken } from './application_ref';
Hence, the origin of PlatformRef becomes clear. In the @angular/core/src/application_ref.d.ts file, we encounter:
export declare abstract class PlatformRef {
abstract bootstrapModuleFactory<M>(
...
}
export declare class PlatformRef_ extends PlatformRef { ... }
It's established that PlatformRef is defined as an abstract base class, with PlatformRef_ acting as a concrete subclass – albeit without any explicit reference to this particular naming convention. However, per https://www.typescriptlang.org/docs/handbook/classes.html#abstract-classes:
Abstract classes serve as base classes for deriving other classes. Direct instantiation of abstract classes is not permitted.
Considering this information, what exactly does the invocation of platformBrowserDynamic() yield? Is it an Abstract Base Class (ABC)? Or perhaps an attempted invocation of said ABC, contradicting documentation guidelines? If indeed an ABC, the situation worsens given that the immediate call to platformBrowserDynamic initiates an abstract method within that ABC – leading to undefined outcomes. Despite functioning nominally, the mechanics behind its operation leave me perplexed.