## 経緯
[[ts-node]]や[[ts-node-dev]]以外で、[[Node.js]]の[[TypeScript]]実行環境があると目にしたので試してみたくなった。[[Microsoft]]をはじめとするほぼすべてのビッグテックが使っているのが大きい。[[Vite]]も使っている。
## プロジェクト作成
開発のことは一旦考えず、実行のみ試してみる。
```console
mkdir tsx-sandbox
cd tsx-sandbox
npm init -y
corepack enable pnpm
```
## インストール
Getting startedに従う。
<div class="link-card">
<div class="link-card-header">
<img src="https://tsx.is/logo-mini.svg" class="link-card-site-icon"/>
<span class="link-card-site-name">tsx</span>
</div>
<div class="link-card-body">
<div class="link-card-content">
<p class="link-card-title">tsx</p>
<p class="link-card-description">tsx (TypeScript Execute) - The easiest way to run TypeScript in Node.js</p>
</div>
<img src="https://tsx.is/social.png" class="link-card-image" />
</div>
<a href="https://tsx.is/getting-started"></a>
</div>
```console
pnpm add -D tsx
```
## TypeScriptファイル作成
`index.ts` を作成する。
```ts
function sum(x: number, y: number): number {
return x + y;
}
function main() {
var a = 1;
var b = 10;
console.log(`sum(a, b): ${sum(a, b)}`);
}
main();
```
## 実行
```console
pnpm tsx ./index.ts
```
コンパイルしているせいか一瞬だけラグがある。[[Deno]]や[[Bun]]の方が速い。