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
tscor 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
nodeinstead ofdeno, which won't work without compilation. - Not giving execute permissions when accessing files or network resources (use
--allow-read,--allow-netflags). - 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
| Command | Description |
|---|---|
| deno run file.ts | Run a TypeScript file directly |
| deno run --allow-read file.ts | Run with permission to read files |
| deno run --allow-net file.ts | Run with permission to access network |
| deno fmt file.ts | Format TypeScript code |
| deno lint file.ts | Check 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.