Skip to content

getAnnotationArg

Import from @varavel/vdl-plugin-sdk/utils/ir.

function getAnnotationArg(annotations, name): 
  | LiteralValue
  | undefined;

Returns the raw literal argument stored in an annotation.

VDL annotations currently expose a single literal argument. Pair this helper with unwrapLiteral when you need a plain JavaScript value.

Parameters

Parameter Type Description
annotations Annotation[] | undefined Annotation list to search.
name string Annotation name whose argument should be returned.

Returns

| LiteralValue | undefined

The annotation argument as a LiteralValue, or undefined when the annotation or argument is missing.

Example

const arg = getAnnotationArg(field.annotations, "length");
// returns the raw annotation literal, such as { kind: "int", intValue: 64, ... }