Skip to content

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

Additionally, a part can be nullish, which means subsequent parts will use the appropriate conditional access operator e.g. ?..

import { MemberExpression } from "@alloy-js/typescript";
<MemberExpression >
{children}
</MemberExpression>

Props

childrenChildren

Example

<MemberExpression>
<MemberExpression.Part id="base" />
<MemberExpression.Part refkey={rk} nullish />
<MemberExpression.Part symbol={sym} />
<MemberExpression.Part args={["hello", "world"]} />
</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")