VDL Plugin SDK

getAnnotation

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

function getAnnotation(annotations, name): Annotation | undefined;

Returns the first annotation that matches the provided name.

Annotation names are compared exactly as stored in the IR, without adding or removing an @ prefix.

Parameters

ParameterTypeDescription
annotationsAnnotation[] | undefinedAnnotation list to search.
namestringAnnotation name to match.

Returns

Annotation | undefined

The matching annotation, or undefined when it is not present.

Example

const annotation = getAnnotation(field.annotations, "deprecated");
// returns the first `deprecated` annotation or undefined