MemberExpression
Create a member expression from parts. Each part can provide one of the following:
- id: The identifier for the member expression part * refkey: a refkey for a symbol whose name becomes the identifier * symbol: a symbol whose name becomes the identifier part * args: create a method call with the given args * children: arbitrary contents for the identifier part * await: whether to await the value that results from this part of the member expression
Each part can have a nullish prop, which indicates that the part may be null or undefined.
Each part can also have a quoteId prop, which indicates that the identifier of the part should be quoted (i.e. ["foo"] instead of .foo). This is only necessary when providing the children prop, otherwise it is determined automatically.
import { MemberExpression } from "@alloy-js/typescript";
<MemberExpression > {children}</MemberExpression>import { MemberExpression } from "@alloy-js/typescript/stc";
MemberExpression({ }).children(children)| children | Children |
Example
Section titled “Example”<MemberExpression>
<MemberExpression.Part id="base" />
<MemberExpression.Part refkey={rk} nullish />
<MemberExpression.Part symbol={sym} />
<MemberExpression.Part args={["hello", "world"]} />
<MemberExpression.Part>SomeValue</MemberExpression.Part>
</MemberExpression>
Assuming rk is a refkey to a symbol name “prop1”, and sym is a symbol with a name of “prop2”, this will render:
base.prop1?.prop2("hello", "world").SomeValue