Skip to content

Lesson 2 of 9 · 22m

TypeScript-Native, Without Magic

Learn what Deno really does with TypeScript, what type checking means at runtime, and where ESM-only execution changes application design.

Deno is often described as "TypeScript native," which is true and slightly misleading. It does not execute types. TypeScript types are erased before JavaScript runs, exactly as they are everywhere else. The operational difference is that Deno integrates transpilation, module resolution, caching, linting, formatting, testing, and type checking into one toolchain instead of making you assemble five packages and a philosophy.

What happens when you run TypeScript

deno run server.ts
deno check server.ts

deno run strips types and executes JavaScript quickly. deno check performs type analysis. This separation matters in production: a program can run with an unresolved type error if you never type-check it. Make deno check part of CI even when runtime startup looks healthy.

ESM is the center of gravity

Deno's native module model is ECMAScript modules:

import { serve } from "jsr:@std/http/server";
import postgres from "npm:postgres";

export function normalizeHost(host: string): string {
  return host.trim().toLowerCase().replace(/:\d+$/, "");
}

There is no legacy CommonJS loader deciding whether require, exports, or mysterious interop helpers apply. That clarity is one of Deno's best features, but it means old packages with dynamic require, conditional exports abuse, or compile-time monkeypatching can fail in ways Node tolerated.

Import maps are routing tables, not decoration

deno.json can pin aliases and versions:

{
  "imports": {
    "@std/http": "jsr:@std/http@^1.0.0",
    "zod": "npm:zod@^3.24.0"
  },
  "tasks": {
    "dev": "deno run --watch --allow-net=:8080 server.ts",
    "check": "deno check server.ts && deno lint && deno fmt --check"
  }
}

Treat this file as the dependency routing table. Import specifiers in source become stable even when versions move. The mistake is using import maps to hide architectural sprawl: if nobody can tell where utils resolves, you have built a scavenger hunt.

TypeScript does not validate the outside world

A type annotation is not input validation:

type UserInput = { email: string; age: number };
const input = JSON.parse(body) as UserInput;

That as is a lie you told the compiler. Validate boundaries with a schema library or explicit checks. The same warning applies to environment variables, message queue payloads, webhook bodies, and database rows.

Field notes

  • deno run is not a substitute for deno check; use both in CI.
  • Prefer jsr: and npm: specifiers deliberately rather than mixing URL imports, package aliases, and local re-exports without a pattern.
  • TypeScript configuration still matters. strict mode catches the nullability mistakes that become production outages.
  • Decorators and legacy compiler transforms are not magically compatible because files end in .ts.
  • Fast startup does not excuse shipping untyped application seams; it only means the crash happens sooner.

Was this lesson helpful?

Sign in to rate