0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【TypeScript】Cloudflare Workersの開発環境でfetch等の型を適用する

0
Posted at

概要

Node.jsと同様に、Cloudflare WorkersにおいてもFetchの機能などが用意されています。ただ、TypeScriptで開発を行う際、何もしないとCloudflare Workersのfetchに型が適用されません。
どのように型を適用するかのメモ書きが今回の内容となります。

対応方針

Cloudflare WorkersのTypeScriptのドキュメント内に記載のあるwrangler typesを使用します。@cloudflare/workers-typesというパッケージも用意されてはいますが、公式としては2026年3月時点ではwrangler typesを推奨しているようです。

対応内容

上記のドキュメントにある通りですが、npx wrangler typesを実行するとworker-configuration.d.tsの型ファイルが生成されます。あとはこの型ファイルを以下の通り、tsconfigに追加します。

{
  "compilerOptions": {
    "types": ["./worker-configuration.d.ts"]
  }
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?