Skip to content
On this page

VCL vs TypeScript (quick comparison)

A side‑by‑side to help TS users orient in VCL.

Cheat sheet

TopicVCLTypeScript
BlocksSignificant indentation + trailing . ends statementsBraces + semicolons (optional)
Imports/modulesfoo::bar namespaces; modules resolved by linker/registryimport { x } from './mod' ES modules
EffectsBuilt‑ins: fetch/send/store/log; runtime provides implementationsUse fetch, libs, or framework APIs
AsyncEffects implicitly async; compiled TS uses promisesasync/await explicit
TruthinessOnly none is falsyfalse, 0, "", null, undefined, NaN
Nullishnonenull / undefined
TypesStructural; mostly inferred; explicit annotations limited todayRich annotations, interfaces, generics, utility types
Handlersdefine <name>. with implicit ctx record; common for events/HTTPFunctions/handlers per framework (e.g., Next route handlers)
Returnsreturn <value>. (or implicit last send/ensure)return value;
ToolingCLI + VCL VS Code extensionTS compiler + tsserver/VS Code

Hello, request handler

VCL:

text
define hello.
  let { name } = ctx.
  let greeting = "Hello, " + name + "!".
  send { status: 200, body: { message: greeting } }.

Compiled TS (conceptual shape):

ts
export async function on_http_GET_/hello(ctx: { name: string }) {
  const greeting = `Hello, ${ctx.name}!`;
  return { status: 200, body: { message: greeting } };
}

Control flow

VCL:

text
when user.is_admin.
  log "admin".
else.
  log "user".

TS:

ts
if (user.is_admin) {
  console.log("admin");
} else {
  console.log("user");
}

Effects & runtime

  • In VCL you call fetch/send/store/log; the runtime adapter maps these to platform primitives (HTTP, DB, logging).
  • In TS you call platform APIs directly; there’s no built‑in effect vocabulary.

Modules

  • VCL: import auth::session. and call auth::session::current ctx.
  • TS: import { current } from './auth/session' and call current(ctx).

Error handling

  • ensure / validate / expect short‑circuit; the runtime turns them into errors/responses.
  • TS uses throw/try-catch or Result/Promise patterns.

When to pick which

  • Write in VCL for terse, effect‑first handlers and generate TS for integration.
  • Drop to TS for ecosystem/library breadth or advanced typing features not yet in VCL.