From afd4a4ed4d9b8baec64141569ff249bd7df92f54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Ortiz=20Garc=C3=ADa?= Date: Wed, 13 Mar 2019 17:02:31 -0700 Subject: [PATCH] feat(core): Add "AbstractType" interface (#29295) This new interface will match classes whether they are abstract or concrete. Casting as `AbstractType` will return a type that isn't newable. This type will be used to match abstract classes in the `get()` functions of `Injector` and `TestBed`. Type isn't used yet so this isn't a breaking change. Issue #26491 PR Close #29295 --- packages/core/src/core.ts | 2 +- packages/core/src/interface/type.ts | 10 ++++++++++ tools/public_api_guard/core/core.d.ts | 4 ++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/packages/core/src/core.ts b/packages/core/src/core.ts index ac379e2bb9..e49543bd34 100644 --- a/packages/core/src/core.ts +++ b/packages/core/src/core.ts @@ -29,7 +29,7 @@ export * from './platform_core_providers'; export {TRANSLATIONS, TRANSLATIONS_FORMAT, LOCALE_ID, MissingTranslationStrategy} from './i18n/tokens'; export {ApplicationModule} from './application_module'; export {wtfCreateScope, wtfLeave, wtfStartTimeRange, wtfEndTimeRange, WtfScopeFn} from './profile/profile'; -export {Type} from './interface/type'; +export {AbstractType, Type} from './interface/type'; export {EventEmitter} from './event_emitter'; export {ErrorHandler} from './error_handler'; export * from './core_private_export'; diff --git a/packages/core/src/interface/type.ts b/packages/core/src/interface/type.ts index f99a53df75..faec83d8a1 100644 --- a/packages/core/src/interface/type.ts +++ b/packages/core/src/interface/type.ts @@ -22,6 +22,16 @@ export function isType(v: any): v is Type { return typeof v === 'function'; } +/** + * @description + * + * Represents an abstract class `T`, if applied to a concrete class it would stop being + * instantiatable. + * + * @publicApi + */ +export interface AbstractType extends Function { prototype: T; } + export interface Type extends Function { new (...args: any[]): T; } export type Mutable = { diff --git a/tools/public_api_guard/core/core.d.ts b/tools/public_api_guard/core/core.d.ts index 905f9020d5..8e4d861e77 100644 --- a/tools/public_api_guard/core/core.d.ts +++ b/tools/public_api_guard/core/core.d.ts @@ -1,3 +1,7 @@ +export interface AbstractType extends Function { + prototype: T; +} + export interface AfterContentChecked { ngAfterContentChecked(): void; }