VDL Plugin SDK

unwrapLiteral

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

function unwrapLiteral<T>(value): T;

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 ParameterDefault type
Tunknown

Parameters

ParameterTypeDescription
valueLiteralValueThe 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 }