Skip to content

FunctionExpression

A TypeScript function expression.

import { FunctionExpression } from "@alloy-js/typescript";
<FunctionExpression
async
parameters={ParameterDescriptor[] | string[]}
parametersChildren={Children}
returnType={Children}
typeParameters={TypeParameterDescriptor[] | string[]}
typeParametersChildren={Children}
>
{children}
</FunctionExpression>
asyncoptional boolean
childrenoptional Children
parametersoptional ParameterDescriptor[] | string[]The parameters to the function. Can be an array of strings for parameters which don’t have a type or a default value. Otherwise, it’s an array of ParameterDescriptors.
parametersChildrenoptional ChildrenRaw content to be used as the parameter list.
returnTypeoptional ChildrenThe return type of the function.
typeParametersoptional TypeParameterDescriptor[] | string[]The type parameters for the function. Can be an array of strings for type parameters which don’t have any constraints or a default type, otherwise it’s an array of TypeParameterDescriptors.
typeParametersChildrenoptional ChildrenRaw content to be used as the type parameter list.

Providing parameters and type parameters can be accomplished in one of three ways:

  1. As an array of ParameterDescriptors or TypeParameterDescriptors.
  2. As raw content via the parametersChildren or typeParametersChildren props.
  3. As a child of this component via the [unresolved link] or [unresolved link] components.
<FunctionExpression async parameters={[{ name: "a", type: "number" }, { name: "b", type: "number" }]}>
  return a + b;
<FunctionExpression>

renders to

async function (a, b) { return a + b; }