Skip to content
    TS
    TypeScript Playground
    Compiled JavaScript
    Console
    Output will appear here after execution.
    ReadyTypeScript v5.8.3
    Ln 1, Col 1© WebFiddle.xyz

    TypeScript Online Compiler and TS Playground

    This TypeScript online compiler turns TypeScript into JavaScript in your browser with the TypeScript 5.8 compiler, runs the result and prints its console output. It is an independent TS playground built by WebFiddle, not the official TypeScript Playground at typescriptlang.org/play. The compiled JavaScript and the console update about a second after you stop typing, and the editor underlines type errors as you write. Use it to try a language feature, see what an annotation compiles to or share a snippet, without installing Node.js, npm or a tsconfig.json file.

    How to use the TypeScript online compiler

    1. Type or paste TypeScript into the editor. A starter example is loaded by default.
    2. Watch the Compiled JavaScript panel, which shows the emitted code for the selected target about a second after you stop typing.
    3. Read console output and syntax errors in the Console panel. Type errors appear as red underlines in the editor; hover one to read the message.
    4. Open Compiler Settings (the sliders icon) to change the target or turn strict mode off.
    5. Turn off auto-run with the lightning icon if your code is slow or has side effects, then press Run when you are ready.
    6. Load an example from the Examples menu, or press Share to copy a link to your code.

    Features

    • TypeScript 5.8 compiler from the official typescript npm package, bundled into the page
    • Side-by-side view of your TypeScript and the compiled JavaScript
    • Console panel for console.log, info, warn and error, including output from async code you await
    • Auto-run one second after you stop typing, with a toggle to switch to manual runs
    • Compiler settings for the output target (ES2015, ES2020 or ESNext) and strict mode
    • Monaco editor with autocompletion, hover information and red underlines for type errors
    • 8 built-in examples: Hello TypeScript, Interfaces & Types, Generics, Enums & Unions, Async / Await, Utility Types, Classes & Inheritance, Type Guards
    • Share button that stores your code in a compressed URL

    What works and what doesn’t

    • Type errors do not stop your code from running. Each run transpiles the file on its own, like isolatedModules, so the Console panel lists syntax errors only and type errors are shown in the editor.
    • Code runs as a single script, so import and export statements cause a syntax error and npm packages cannot be used.
    • Only console.log, info, warn and error are captured. Methods such as console.table are not available and raise a runtime error.
    • Output appears when the top-level code finishes. Logs from callbacks that run later, such as a setTimeout you do not await, are not shown.
    • Code runs in the page itself rather than in a worker, so an infinite loop freezes the tab until you reload it.
    • The editor underlines come from Monaco's built-in TypeScript service, which can be a different TypeScript version from the 5.8 compiler that produces the output.

    Example programs

    Generic function with a constraint

    T extends HasId lets findById accept any object that has a numeric id while keeping the full element type in the return value.

    interface HasId {
      id: number;
    }
    
    function findById<T extends HasId>(items: T[], id: number): T | undefined {
      return items.find((item) => item.id === id);
    }
    
    const users = [
      { id: 1, name: "Ada" },
      { id: 2, name: "Linus" },
    ];
    
    console.log(findById(users, 2)?.name); // "Linus"
    

    Discriminated union with an exhaustive switch

    Assigning the leftover value to never makes the compiler flag any shape you forget to handle. Switch the target to ES2015 to see how the ** operator is compiled.

    type Shape =
      | { kind: "circle"; radius: number }
      | { kind: "rect"; width: number; height: number };
    
    function area(shape: Shape): number {
      switch (shape.kind) {
        case "circle":
          return Math.PI * shape.radius ** 2;
        case "rect":
          return shape.width * shape.height;
        default: {
          const unreachable: never = shape;
          return unreachable;
        }
      }
    }
    
    console.log(area({ kind: "rect", width: 3, height: 4 })); // 12
    console.log(area({ kind: "circle", radius: 1 }).toFixed(2)); // "3.14"
    

    Compile TypeScript to JavaScript with satisfies and async/await

    satisfies checks the object against a type without widening its properties, so config.retries stays a number. The playground wraps your code in an async function, so the final await runs even if the editor underlines it.

    const config = {
      retries: 3,
      endpoint: "/api/items",
    } satisfies Record<string, string | number>;
    
    const wait = (ms: number) =>
      new Promise<void>((resolve) => setTimeout(resolve, ms));
    
    async function main(): Promise<void> {
      for (let attempt = 1; attempt <= config.retries; attempt++) {
        await wait(200);
        console.log("Attempt " + attempt + " of " + config.retries + " to " + config.endpoint);
      }
    }
    
    await main();
    

    Frequently asked questions

    What is a TypeScript online compiler?

    A TypeScript online compiler turns TypeScript into JavaScript as you type and runs the result, without setting up Node.js, npm or a tsconfig.json file. This one, a TS playground that works in your browser, uses the TypeScript 5.8 compiler, shows the emitted JavaScript beside your code and prints console output underneath it.

    Is this the official TypeScript Playground?

    No. The official TypeScript Playground is maintained by the TypeScript team at typescriptlang.org/play. This TS playground is an independent online compiler built by WebFiddle: it bundles the TypeScript 5.8 compiler from the typescript npm package, runs the compiled JavaScript and prints console output underneath, and it shares code through a compressed link.

    Which TypeScript version does this online compiler use?

    It bundles the TypeScript 5.8 compiler from the typescript npm package, and the exact build number is shown in the status bar at the bottom of the playground. Language features released up to TypeScript 5.8, such as satisfies, const type parameters and standard decorators, compile here.

    Why does my code run even though it has type errors?

    The playground transpiles each file in isolation, the same way tools such as Babel and esbuild remove types, so type errors do not block the output. They are still reported: the editor underlines them in red and hovering an underline shows the message. Syntax errors are listed in the Console panel.

    How do I compile TypeScript to JavaScript and see the output?

    Type your code in the left editor. About one second after you stop typing, the Compiled JavaScript panel shows the emitted code for the target chosen in Compiler Settings: ES2015, ES2020 or ESNext. With ES2015, for example, optional chaining and the ** operator are rewritten into older equivalent JavaScript.

    Can I import npm packages in the TypeScript playground?

    No. Your code runs as a single script inside the page, so import and export statements cause a syntax error. Built-in JavaScript objects and browser APIs such as Map, Promise, JSON and fetch are available. For code that depends on npm packages, use a local project with the typescript package installed.

    Is my TypeScript code sent to a server?

    No. Compiling and running both happen in your browser, and nothing is uploaded while you type or run code. Your code only leaves your device if you press Share, which puts it into a compressed link that you choose to send. The playground does not keep a copy on a WebFiddle server.

    Embed this sandbox

    Paste this iframe into any web page and readers can run code without leaving it. The snippet travels in the URL, so there is nothing to host and no account to create. Open the sandbox, write your example, press Share, then append that link’s query string to the embed URL to preload it.

    <iframe src="https://webfiddle.xyz/embed/typescript" width="100%" height="480" loading="lazy"
            style="border:1px solid #ddd;border-radius:8px"
            title="WebFiddle typescript sandbox"></iframe>
    Preview the embed

    Related articles

    Related sandboxes

    Official documentation