ir
Functions
getAnnotation()
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
annotations
Annotation list to search.
Annotation[] | undefined
name
string
Annotation 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
getAnnotationArg()
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
annotations
Annotation list to search.
Annotation[] | undefined
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, ... }
unwrapLiteral()
Resolves a LiteralValue into its native JavaScript representation.
Pass a generic when you already know the expected shape.
Omit it to get unknown and narrow the result yourself.
The generic only affects TypeScript types. It does not validate the runtime value.
Type Parameters
T
T = unknown
Parameters
value
The VDL literal to convert.
Returns
T
The recursively unwrapped JavaScript value.
Examples
const raw = unwrapLiteral({
position: { file: "schema.vdl", line: 1, column: 1 },
kind: "string",
stringValue: "hello",
});
// returns "hello"
const value = unwrapLiteral<{ enabled: boolean }>(
{
position: { file: "schema.vdl", line: 1, column: 1 },
kind: "object",
objectEntries: [
{
position: { file: "schema.vdl", line: 1, column: 1 },
key: "enabled",
value: {
position: { file: "schema.vdl", line: 1, column: 1 },
kind: "bool",
boolValue: true,
},
},
],
},
);
// returns { enabled: true }