0
0
DenoHow-ToBeginner ยท 3 min read

Does Deno Support TypeScript Natively? Quick Guide

Yes, Deno supports TypeScript natively. You can run TypeScript files directly with deno run without needing a separate compilation step or configuration.
๐Ÿ“

Syntax

To run a TypeScript file in Deno, use the deno run command followed by the filename. Deno automatically compiles and executes the TypeScript code.

  • deno run filename.ts: Runs the TypeScript file directly.
  • No need for tsc or manual compilation.
  • Deno handles type checking and compilation internally.
bash
deno run example.ts
๐Ÿ’ป

Example

This example shows a simple TypeScript program run directly by Deno. It prints a greeting message to the console.

typescript
console.log("Hello from TypeScript in Deno!");
Output
Hello from TypeScript in Deno!
โš ๏ธ

Common Pitfalls

Some common mistakes when running TypeScript in Deno include:

  • Trying to run files with node instead of deno, which won't work without compilation.
  • Not giving execute permissions when accessing files or network resources (use --allow-read, --allow-net flags).
  • Expecting a separate build step like in other TypeScript setups; Deno does this automatically.
bash
Wrong way:
node example.ts

Right way:
deno run example.ts
๐Ÿ“Š

Quick Reference

CommandDescription
deno run file.tsRun a TypeScript file directly
deno run --allow-read file.tsRun with permission to read files
deno run --allow-net file.tsRun with permission to access network
deno fmt file.tsFormat TypeScript code
deno lint file.tsCheck TypeScript code for issues
โœ…

Key Takeaways

Deno runs TypeScript files directly without manual compilation.
Use the command 'deno run filename.ts' to execute TypeScript code.
Deno automatically handles type checking and compilation internally.
Remember to add permission flags for file or network access.
Do not use 'node' to run TypeScript files in Deno projects.