ClassDeclaration
Create a TypeScript class declaration.
import { ClassDeclaration } from "@alloy-js/typescript";
<ClassDeclaration default doc={Children} export extends={Children} flags={OutputSymbolFlags} kind={"type" | "value"} metadata={Record<string, unknown>} name="string" refkey={Refkey | Refkey[]} />
import { ClassDeclaration } from "@alloy-js/typescript/stc";
ClassDeclaration({ default: boolean, doc: Children, export: boolean, extends: Children, flags: OutputSymbolFlags, kind: "type" | "value", metadata: Record<string, unknown>, name: string, refkey: Refkey | Refkey[],}).children(children)
Props
children | optionalChildren |
default | optionalboolean Whether this is the default export of the module. |
doc | optionalChildren Documentation for this declaration |
export | optionalboolean Whether to export this declaration from the module. |
extends | optionalChildren |
flags | optionalOutputSymbolFlags Flags for the symbol created by this component. |
kind | optional”type” | “value” Whether this is a declaration of a type (e.g. interface, type alias) or a value (e.g. var, const, let). |
metadata | optionalRecord<string, unknown> Arbitrary metadata about this declaration. |
name | string The base name of this declaration. May change depending on naming policy and any conflicts. |
refkey | optionalRefkey | Refkey[] The refkey or array of refkeys for this declaration. |
Remarks
Example
const myPetRefkey = refkey();const Animal = refkey();const staticMember = refkey();const instanceMember = refkey();
<ClassDeclaration name="Animal" refkey={Animal}> <ClassMember public static name="something" type="string" refkey={staticMember}> "hello" </ClassMember> <ClassMember public name="kind" type="string" /> <ClassMember public name="name" type="string" refkey={instanceMember} /> <ClassConstructor parameters="name: string"> this.name = name; </ClassConstructor></ClassDeclaration>
<VarDeclaration const name="myPet" refkey={myPetRefkey}> new {Animal}();</VarDeclaration>
{staticMember}; // Animal.something<MemberReference path={[myPetRefkey, instanceMember]} /> // myPet.name{member(myPetRefkey, instanceMember)} // other option?