Deno TypeScript with Claude Code
Learn about deno typescript using Claude Code. Practical tips and code examples included.
Deno開発をClaude Codeで効率化する
Denoはセキュリティファーストなモダンランタイムです。TypeScriptをネイティブサポートし、パーミッションモデルによる安全な実行環境を提供します。Claude Codeと組み合わせれば、Denoの独自機能も素早く活用できます。
プロジェクトの初期設定
> DenoでWebアプリを作成して。
> Freshフレームワークを使って、deno.jsonの設定もして。
// deno.json
{
"lock": false,
"tasks": {
"dev": "deno run -A --watch=static/,routes/ dev.ts",
"build": "deno run -A dev.ts build",
"start": "deno run -A main.ts",
"test": "deno test -A --coverage=coverage",
"lint": "deno lint",
"fmt": "deno fmt"
},
"imports": {
"$fresh/": "https://deno.land/x/[email protected]/",
"$std/": "https://deno.land/[email protected]/",
"preact": "https://esm.sh/[email protected]",
"preact/": "https://esm.sh/[email protected]/"
},
"compilerOptions": {
"jsx": "react-jsx",
"jsxImportSource": "preact"
}
}
パーミッションモデルの活用
Denoはデフォルトですべてのアクセスを拒否します。
> ファイル読み取りとネットワークアクセスだけを許可した
> APIサーバーを作って。最小権限の原則で設定して。
// server.ts
// 実行: deno run --allow-net=:8000 --allow-read=./data server.ts
import { serve } from "$std/http/server.ts";
const handler = async (req: Request): Promise<Response> => {
const url = new URL(req.url);
if (url.pathname === "/api/config") {
const data = await Deno.readTextFile("./data/config.json");
return new Response(data, {
headers: { "content-type": "application/json" },
});
}
if (url.pathname === "/api/items") {
const dir = Deno.readDir("./data/items");
const items = [];
for await (const entry of dir) {
if (entry.isFile && entry.name.endsWith(".json")) {
const content = await Deno.readTextFile(
`./data/items/${entry.name}`
);
items.push(JSON.parse(content));
}
}
return Response.json(items);
}
return new Response("Not Found", { status: 404 });
};
serve(handler, { port: 8000 });
Freshでアイランドアーキテクチャ
> Freshのアイランドコンポーネントでカウンターを作って。
> サーバーサイドとクライアントサイドの分離を意識して。
// routes/index.tsx
import Counter from "../islands/Counter.tsx";
export default function Home() {
return (
<div class="max-w-screen-md mx-auto p-4">
<h1 class="text-4xl font-bold">Deno Fresh App</h1>
<Counter start={0} />
</div>
);
}
// islands/Counter.tsx
import { useSignal } from "@preact/signals";
interface CounterProps {
start: number;
}
export default function Counter({ start }: CounterProps) {
const count = useSignal(start);
return (
<div class="flex gap-4 items-center">
<button onClick={() => count.value--}>-</button>
<span class="text-2xl">{count}</span>
<button onClick={() => count.value++}>+</button>
</div>
);
}
テストとカバレッジ
// server_test.ts
import { assertEquals } from "$std/assert/assert_equals.ts";
Deno.test("API health check", async () => {
const res = await fetch("http://localhost:8000/api/config");
assertEquals(res.status, 200);
const data = await res.json();
assertEquals(typeof data, "object");
});
Deno.test("file operations with permissions", async () => {
const content = await Deno.readTextFile("./data/config.json");
const config = JSON.parse(content);
assertEquals(config.version !== undefined, true);
});
Deno Deployへのデプロイ
# Deno DeployのCLI
deno install -A jsr:@deno/deployctl
# デプロイ
deployctl deploy --project=my-app --entrypoint=main.ts
Summary
DenoのセキュリティモデルとTypeScriptネイティブサポートは、安全で快適な開発体験を提供します。Claude Codeを使えば、パーミッション設定やFreshの独自パターンも効率的に習得できます。TypeScript開発のコツやセキュリティ監査ガイドも参考にしてください。
Denoの詳細はDeno公式ドキュメントを参照してください。
#Claude Code
#Deno
#TypeScript
#ランタイム
#security
Related Posts
Use Cases
Use Cases
How to Supercharge Your Side Projects with Claude Code [With Examples]
How to Supercharge Your Side Projects with Claude Code [With Examples]. A practical guide with code examples.
Use Cases
Use Cases
How to Automate Refactoring with Claude Code
Learn how to automate refactoring using Claude Code. Includes practical code examples and step-by-step guidance.
Use Cases
Use Cases
Complete CORS Configuration Guide with Claude Code
Learn about complete cors configuration guide using Claude Code. Practical tips and code examples included.