Modern Scripting with TypeScript: Deno, Bun

Introduction
In order to automate repetitive or complex tasks, developers write scripts using a scripting language. Usually, this language is interpreted and doesn't require preparation (such as compilation).
Using these scripts, developers tend to automate their workspace (manual build, deployment to development environment) as well as daily life (hobby projects, operating system tools). More advanced projects can make use of CI/CD pipelines to automate the lifecycle of their applications.
JavaScript is originally used in web development for frontend (web browser) scripting, but with the advance of technologies such as Node.js, it became prevalent in backend development.
Typescript is a language based around JavaScript to provide type annotations, and thus allow to write more complex applications with better tooling and safety.
We will see in this article how we can use Typescript like an interpreted scripting language without extra preparation.
Using Deno
Deno is a modern JavaScript runtime compatible with Node.js with first-class TypeScript support.
Installation
You can quickly install and try out Deno with the following command if you have node.js / npm already installed, but it's recommended to install using the script provided in the official installation page:
npm install -g deno
Required adaptations
Node module imports should have the "node:" prefix.
You may need to use import instead of require depending on the module system you are using.
Scripts using CommonJS features, such as require(), module.exports, __filename and __dirname have to be renamed to use the .cts extension.
Scripts using ECMAScript Module (ESM) features such as import / export statements, top level await and import.meta can be renamed to use the .mts extension.
Running a TypeScript script
deno -A <path-to-your-script.ts>
As deno introduced a more secure model for Input/Output and network operations, it's necessary to use the -A flag to allow all required permissions, which is already the case for Node.js.
Docker image
Official docker image documentation and samples are provided in this page.
Other features
You can also use the compile feature of deno to make an executable binary runnable without having Deno installed.
Using Bun
Bun is a versatile runtime for JavaScript designed as a drop-in replacement for Node.js.
Installation
You can quickly install and try out Bun with the following command if you have node.js / npm already installed, but it's recommended to install using the script provided in the official installation page:
npm install -g bun
Running a TypeScript script
bun <path-to-your-script.ts>
Docker image
The official docker image can be the basis for your build or runtime scripts:
FROM oven/bun:latest