unwrapLiteral
Import from @varavel/vdl-plugin-sdk/utils/ir.
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
| Type Parameter | Default type |
|---|---|
T |
unknown |
Parameters
| Parameter | Type | Description |
|---|---|---|
value |
LiteralValue |
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 }