@@ -5,7 +5,10 @@ import { ApiItem, IApiItemJson, IApiItemConstructor, IApiItemOptions } from '../
55import { ApiDocumentedItem } from '../model/ApiDocumentedItem' ;
66import { Excerpt , ExcerptToken , IExcerptTokenRange , IDeclarationExcerpt , ExcerptName } from './Excerpt' ;
77
8- /** @public */
8+ /**
9+ * Constructor options for {@link (ApiDeclarationMixin:interface)}.
10+ * @public
11+ */
912export interface IApiDeclarationMixinOptions extends IApiItemOptions {
1013 declarationExcerpt : IDeclarationExcerpt ;
1114}
@@ -17,18 +20,51 @@ const _excerpt: unique symbol = Symbol('ApiDeclarationMixin._excerpt');
1720const _excerptTokens : unique symbol = Symbol ( 'ApiDeclarationMixin._excerptTokens' ) ;
1821const _embeddedExcerptsByName : unique symbol = Symbol ( 'ApiDeclarationMixin._embeddedExcerptsByName' ) ;
1922
20- /** @public */
23+ /**
24+ * The mixin base class for API items that have an associated source code excerpt containing a
25+ * TypeScript declaration.
26+ *
27+ * @remarks
28+ *
29+ * This is part of the {@link ApiModel} hierarchy of classes, which are serializable representations of
30+ * API declarations. The non-abstract classes (e.g. `ApiClass`, `ApiEnum`, `ApiInterface`, etc.) use
31+ * TypeScript "mixin" functions (e.g. `ApiDeclarationMixin`, `ApiItemContainerMixin`, etc.) to add various
32+ * features that cannot be represented as a normal inheritance chain (since TypeScript does not allow a child class
33+ * to extend more than one base class). The "mixin" is a TypeScript merged declaration with three components:
34+ * the function that generates a subclass, an interface that describes the members of the subclass, and
35+ * a namespace containing static members of the class.
36+ *
37+ * Most `ApiItem` subclasses have declarations and thus extend `ApiDeclarationMixin`. Counterexamples include
38+ * `ApiModel` and `ApiPackage`, which do not have any corresponding TypeScript source code.
39+ *
40+ * @public
41+ */
2142// tslint:disable-next-line:interface-name
2243export interface ApiDeclarationMixin extends ApiItem {
44+ /**
45+ * The source code excerpt where the API item is declared.
46+ */
2347 readonly excerpt : Excerpt ;
2448
49+ /**
50+ * The individual source code tokens that comprise the main excerpt.
51+ */
2552 readonly excerptTokens : ReadonlyArray < ExcerptToken > ;
2653
54+ /**
55+ * A collection of named embedded excerpts. For example, if `ApiDeclarationMixin.excerpt` is a property
56+ * declaration, then `embeddedExcerptsByName` might contain an embedded excerpt corresponding to the
57+ * type of the property.
58+ */
2759 readonly embeddedExcerptsByName : ReadonlyMap < ExcerptName , Excerpt > ;
2860
2961 /** @override */
3062 serializeInto ( jsonObject : Partial < IApiItemJson > ) : void ;
3163
64+ /**
65+ * Returns a member of the {@link (ApiDeclarationMixin:interface).embeddedExcerptsByName} map,
66+ * or throws an exception if was not found.
67+ */
3268 getEmbeddedExcerpt ( name : ExcerptName ) : Excerpt ;
3369
3470 /**
@@ -38,7 +74,14 @@ export interface ApiDeclarationMixin extends ApiItem {
3874 getExcerptWithModifiers ( ) : string ;
3975}
4076
41- /** @public */
77+ /**
78+ * Mixin function for {@link (ApiDeclarationMixin:interface)}.
79+ *
80+ * @param baseClass - The base class to be extended
81+ * @returns A child class that extends baseClass, adding the {@link (ApiDeclarationMixin:interface)} functionality.
82+ *
83+ * @public
84+ */
4285export function ApiDeclarationMixin < TBaseClass extends IApiItemConstructor > ( baseClass : TBaseClass ) :
4386 TBaseClass & ( new ( ...args : any [ ] ) => ApiDeclarationMixin ) { // tslint:disable-line:no-any
4487
@@ -148,8 +191,20 @@ export function ApiDeclarationMixin<TBaseClass extends IApiItemConstructor>(base
148191 return MixedClass ;
149192}
150193
151- /** @public */
194+ /**
195+ * Static members for {@link (ApiDeclarationMixin:interface)}.
196+ * @public
197+ */
152198export namespace ApiDeclarationMixin {
199+ /**
200+ * A type guard that tests whether the specified `ApiItem` subclass extends the `ApiDeclarationMixin` mixin.
201+ *
202+ * @remarks
203+ *
204+ * The JavaScript `instanceof` operator cannot be used to test for mixin inheritance, because each invocation of
205+ * the mixin function produces a different subclass. (This could be mitigated by `Symbol.hasInstance`, however
206+ * the TypeScript type system cannot invoke a runtime test.)
207+ */
153208 export function isBaseClassOf ( apiItem : ApiItem ) : apiItem is ApiDeclarationMixin {
154209 return apiItem . hasOwnProperty ( _excerpt ) ;
155210 }
0 commit comments