DEV Community

Dina
Dina

Posted on

Learning TypeScript? try Deno

Deno is modern, fast and secure runtime that supports TypeScript and JavaScript natively. It is very simple to setup and use. It is very welcoming to JS developers because its very easy to get started.

Install

As simple as brew install deno on a mac and choco install deno on a windows machine. Detailed instruction on installation is here.

Run

Deno can run any JS or TS file hosted on the internet.

$ deno run https://deno.land/std/examples/welcome.ts
Enter fullscreen mode Exit fullscreen mode

Or, let us write any valid TypeScript file locally

// save this as welcome.ts

interface Account {
  id: number
  displayName: string
  version: 1
}

function welcome(user: Account) {
  console.log('Welcome,', user.displayName)
}

welcome({ id: 1, displayName: 'Dina', version: 1 })
Enter fullscreen mode Exit fullscreen mode

Save the file above and run it directly as shown below. Deno takes care of compiling and executing the code. To start out, you don't have to deal will .tsconfig files or running tsc etc. psst, if you are in a hurry and want to learn TS and not interested in Deno, you could use TS repl and execution environment called ts-node

$ deno run welcome.ts

Check file:///Users/dina/dev/try-deno/welcome.ts
Welcome, Dina
Enter fullscreen mode Exit fullscreen mode

Developer Experience

Deno offers a great DX by providing tools like code linters, formatters and test runners all in the deno executable.

Lint

$ deno lint

(prefer-const) `order` is never reassigned
let order = new Order()
    ^^^^^
    at /Users/dina/try-deno/design-patterns/state.ts:106:4

    hint: Use `const` instead
    help: for further information visit https://lint.deno.land/#prefer-const

Found 24 problems
Checked 25 files

Enter fullscreen mode Exit fullscreen mode

Format

$ deno fmt

/Users/dina/try-deno/design-patterns/decorator.ts
/Users/dina/try-deno/design-patterns/state.ts
Checked 30 files
Enter fullscreen mode Exit fullscreen mode

Test

$ deno test feature.spec.ts
Enter fullscreen mode Exit fullscreen mode

My Two Cents

I don't think Node.js is going away any time soon. Deno is a great alternative but its still under heavy development. Node.js has a huge ecosystem of libraries and utilities which are yet to be converted or made available to Deno. Good thing is introduction of Deno has led to maturing of Node.js since there wasn't many competition to it before. What slice of web is deno going to get? only time will tell. 👋

Top comments (1)

Collapse
 
tmchuynh profile image
Tina Huynh

Thanks for sharing