Upgrade to Pro — share decks privately, control downloads, hide ads and more …

tsc.rip を支える技術 / Kyoto.なんか #8

Avatar for Susisu Susisu
August 22, 2026

tsc.rip を支える技術 / Kyoto.なんか #8

Avatar for Susisu

Susisu

August 22, 2026

More Decks by Susisu

Other Decks in Programming

Transcript

  1. tsc.rip • 2026 年 7 月 8 日に TypeScript 7.0

    がリリース • コンパイラ (tsc) の実装が TypeScript から Go に移植され高速化 • tsc.rip はこれを記念して作った Web サイト
  2. tsc.rip を支える技術 • AWS 静的サイト 激安 • CloudFront • Lambda

    (Function URL) • Go 製 Web サーバー + Lambda Web Adapter
  3. tsc.rip を支える技術 • AWS 静的サイト 激安 • CloudFront S3 で良いのでは?

    • Lambda (Function URL) • Go 製 Web サーバー + Lambda Web Adapter
  4. tsc.rip を支える技術 • AWS 静的サイト 激安 • CloudFront CloudFront Functions

    で 向き先の S3 オブジェクトを 変えたら良いのでは? • Lambda (Function URL) • Go 製 Web サーバー + Lambda Web Adapter
  5. tsc.rip を支える技術 • AWS 静的サイト 激安 • CloudFront 静的??? •

    Lambda (Function URL) • Go 製 Web サーバー + Lambda Web Adapter
  6. tsc.rip を支える技術 • AWS 静的サイト 激安 • CloudFront • Lambda

    (Function URL) 主犯格とみられる人物 • Go 製 Web サーバー + Lambda Web Adapter
  7. tsc.rip を支える技術 (裏) • Go 製 Web サーバー • typescript-go

    を組み込み • リクエストを型に変換 → 型を評価 → 型をレス • TypeScript の型で書かれたアプリケーション ポ • export type Handle<Req> = Res; ンスに変換
  8. Compiler API • サーバーにコンパイラ自体をライブラリとして組み込む • TypeScript 実装では API が公開されている •

    Go 実装では (少なくとも現時点では) 非公開 (internal 以下) だが、 ハックすると無理やり使うことはできる
  9. Compiler API // server/typeeval/go.mod // github.com/microsoft/typescript-go を自称すると internal 以下も使える module

    github.com/microsoft/typescript-go/_tscrip/typeeval // ... require github.com/microsoft/typescript-go v0.0.0-20260708042240-2bd066d87f5b // typescript/v7.0.2 // server/go.mod module github.com/susisu/tsc.rip/server // ... // github.com/microsoft/typescript-go/_tscrip/typeeval は公開なので使える replace github.com/microsoft/typescript-go/_tscrip/typeeval => ./typeeval
  10. 型レベル Web アプリ • アプリ本体はリクエストを引数に取ってレス ンスを返す型エイリアス • export type Handle<Req>

    = Res; • ルーティングやヘッダ、 ディの解釈などは基本的に全てアプリ側で実装 • Content-Length の計算など一部 Go 側に任せているものもある ートしていないので実用には向かない ポ ポ ボ • ストリームや副作用はサ
  11. 型レベル Web アプリ export type Routes<Req extends req.Request> = {

    "/": { GET: (( Req["headers"] extends { accept: infer Accept extends string } ? accept.Negotiate<Accept, ["text/plain", "text/html"]> : "text/plain" ) extends "text/html" ? res.HTML<200, `<!DOCTYPE html>(略)`> : res.Text<200, "The tsc is dead, long live the tsc!\n">) & hs.Link<`<https://susisu.ch>; rel="author"`> & hs.CacheControl<"public, max-age=3600"> & hs.Vary<"accept">; }; // ... };
  12. 型レベル Web アプリ export type Handle<Req extends req.Request> = Routes<Req>

    extends { [_ in Req["path"]]: infer Handlers } ? Handlers extends { [_ in Req["method"]]: infer Res } ? Res : Req["method"] extends "HEAD" ? Handlers extends { GET: infer Res } ? Res : res.Error<405, "Method Not Allowed\n"> & hs.Allow<AllowedMethods<Handlers>> : res.Error<405, "Method Not Allowed\n"> & hs.Allow<AllowedMethods<Handlers>> : res.Error<404, "Not Found\n">; type AllowedMethods<Handlers> = utils.Join< utils.UnionToTuple<"GET" extends keyof Handlers ? "HEAD" | keyof Handlers : keyof Handlers>, ", " >;
  13. まとめ • tsc.rip の裏では型レベル Web アプリケーションが動いていた • TypeScript 万歳 •

    型レベルで Web アプリケーションを書くのはおすすめしません