Deno Tutorial
Deno TypeScript
Deno is a JavaScript and TypeScript runtime.
TypeScript is a strict syntactical superset of JavaScript and adds optional static typing to the language.
TypeScript allows you to write a cleaner JavaScript code.
a
Deno supports both JavaScript and TypeScript as first-class languages at runtime.
Run TypeScript
Before now, we have been writing our examples in JavaScript using the .js
extension. After this tutorial, we may start writing our examples in TypeScript using .ts
extension.
Deno TypeScript Program
The following example codes the random number example with TypeScript, allowing you to provide the max_num
as an argument. Save the file as rand.ts.
File: rand.ts
function generateRandom(max_number: number) {
return Math.ceil(Math.random() * max_number);
}
console.log(generateRandom(5));
Run it the same way you run the .js
files.
deno run rand.ts
What You Should Know at the End of this Chapter
- You should understand that Deno supports both JavaScript and TypeScript as first-class languages and also know their extensions
.js
and.ts
- You should be able to start writing Deno programs with
.ts
extension.