Slide 1

Slide 1 text

コーディングエージェントはTypeScriptの 型エラーをどう自己修正しているの パナソニック エレクトリックワークス株式会社 筧 万里 1 TS Kaigi 2026 ショートセッション

Slide 2

Slide 2 text

自己紹介 2 筧 万里 / Banri Kakehi(@Melonps_) ○ 家庭用燃料電池「エネファーム」のSRE ○ フロントエンド関西コアスタッフ ○ Yamada UIのメンテナー エネファーム

Slide 3

Slide 3 text

なぜこのテーマを話したいの 3 ◎AIにエラー 伝わる仕組みを知って、楽し 開発しよう! 私 Copilot エラー出てるじゃん 早 治してよ! 修正を試みてます 治りません...😭 必要な情報・設定 ないとなぜ上手 い ないの わ らない Type '{ id: string; name: string; }' is missing the following properties from type '{ id: string; name: string; email: string; phone: string; age: number; role: "admin" | "editor" | "viewer"; isActive: boolean; company: { name: string; department: string; position: string; address: { postalCode: string; prefecture: string; city: string; street: string; building?: string | undefined; }; }; address: { postalCode: string;... Valibotで出た長いエラー

Slide 4

Slide 4 text

いざ本編へ... 4 様々なエージェント・ツール・IDEの エラーの読み取り方を見てみましょう tsgo --lsp の話は出て ません!時間足りん った

Slide 5

Slide 5 text

エラー読み取りの二つの形式 5 ◎TypeScript CompilerをCLIで実行 tsc --noEmit ◎LSP(Language Server Protocol)を経由[1] [1]: Language Server Extension Guide | Microsoft, https://code.visualstudio.com/api/language-extensions/language-server-extension-guide

Slide 6

Slide 6 text

Language Server Protocolの さらい 6 エラーを出すコード textDocument/publishDiagnostics const num: number = "hello"; textDocument/didChange

Slide 7

Slide 7 text

z 型エラーはLSPで送る情報のご 一部 7 WarningやHintは 読まないよ Cline Copilot Warningも 読むよ

Slide 8

Slide 8 text

LSP経由でTSのエラー読み取り 8

Slide 9

Slide 9 text

Clineの自己修正の流れ 9

Slide 10

Slide 10 text

vtslsを使用する 10 ◎LSPの入り口はvtsls 用意し、pushされるのを待つ

Slide 11

Slide 11 text

Serenaを使用する 11 ◎LSPをMCPでラップし、AI 読みやすい形でpullで る 11

Slide 12

Slide 12 text

Serenaのシンボル単位の呼び出し例 12 12 curl -s -X POST http://127.0.0.1:8765/mcp \ -H "Content-Type: application/json" \ -H "Accept: application/json, text/event-stream" \ -H "Mcp-Session-Id: $SESSION" \ -d '{ "jsonrpc": "2.0", "id": 3, "method": "tools/call", "params": { "name": "get_diagnostics_for_symbol", "arguments": { "name_path": "UserService", "min_severity": 1 } class UserService { private users: User[] = [] getUserName(id: string): string { const user = this.users.find( u => u.id === id ); return user.name; } } エラーを出すコード

Slide 13

Slide 13 text

Serenaのレスポンス例 13 13 { "src/index.ts": { "Error": { "UserService": [ { "message": "'user' is possibly 'undefined'.", "range": { "start": { "line": 16, "character": 4 }, "end": { "line": 16, "character": 10 } }, "code": 2322, "source": "typescript" }, ] } } } LSPの何行目:何文字目だけの指定よりわ りやすい

Slide 14

Slide 14 text

これ らの関心ごと 14 長す る型エラー / 省略される型エラー はAIの修正精度を下げるのではない ?

Slide 15

Slide 15 text

型シグネチャの展開を行う長いエラー 15 Argument of type '(c: Context) => JSONRespondReturn<{ code: number; message: string; }, 400>' is not assignable to parameter of type 'Handler>>'... Types of property '_data' are incompatible. Type '{ code: number; message: string; }' is missing the following properties from type '{ id: string; name: string; company: { name: string; address: { postalCode: string; prefecture: string; city: string; street: string; building?: string | undefined; }; department: string; position: string; }; address: { postalCode: string; prefecture: string; city: string; street: string; building?: string | undefined; }; email: string; age: number; createdAt: string; updatedAt: string; tags: string[]; phone: string; role: "admin" | "editor" | "viewer"; isActive: boolean; metadata: { [x: string]: string; }; }': id, name, company, address, and 9 more. 世話になっている@hono/zod-openapiを使ったエラーの一部 3000文字 800 token程でClaudeでいう900x900 pxの画像1枚分 らいのトークン量 ... and N more という省略 長い展開

Slide 16

Slide 16 text

tsserver(checker.ts)の省略メカニズム 16 ◎長す るエラーは3パターンで人間むけに省略される 1. and N more:欠けているプロパティ 6個以上で先頭4つだけ表示 2. ... N more ...:約160文字超でユニオン/プロパティ列挙を打ち切り 3. 末尾の「...」:最終文字列 320文字超で末尾を切り捨て これらはTypeScriptの仕様なので ライブラリ・AI側では工夫し ねる...

Slide 17

Slide 17 text

ZodなどのPrettify・Simplify 原因 17 ◎inferの結果を展開済みの型として返すUtility型 export type Prettify = { [K in keyof T ]: T[K]; } & {}; type Base = { id: string; name: string }; type Time = { createdAt: string; updatedAt: string }; type UserRaw = Base & Time; type UserPrettify = Prettify; type UserPrettify = { id: string; name: string; createdAt: string; updatedAt: string; } ○ ホバー: 展開されているほう 読みやすい ○ エラー: 名前 残っているほう 読みやすい ホバーで表示される型 type UserRaw = Base & Time

Slide 18

Slide 18 text

型レベルエラーメッセージ(例:ArkType, Drizzleなど) 18 ◎なぜ型エラーになるの をTSの代入規則任せにしない interface TypeLevelError { readonly $error: M; } type ValidateStatus = S extends DefinedStatusCodes ? S : TypeLevelError<`ステータスコード ${S & number} はrouteのresponsesに定義されていません`>; 型レベルエラーメッセージ Argument of type 'number' is not assignable to parameter of type 'TypeLevelError<"ステータスコード 400 はrouteのresponsesに定義されていません">'.ts(2345) 型エラー 型名がそのままエラー文に出る

Slide 19

Slide 19 text

エラー 削減で ればいいという話ではない 19 ◎エージェント 情報の消費者として追加された →エンジニアとして、これ らも情報の設計 必要 例: ○ diagnosticsは「何 壊れた 」を短 伝える役割に特化し 「何 正しい 」はhoverやcompletionsで取得する ○ 型レベルでエラー文を設計する

Slide 20

Slide 20 text

まとめ 20 ◎エージェント 型エラーをどう読んでいるの ○ Microsoft制のツールとシームレスに連携する形 多い ○ LSPを直接使わず、MCPやToolsでラップするケース 増加 ◎TypeScriptの型情報の出方 修正精度に直結する ○ 人間のための型設計 結果としてAIにも通用する ○ AIフレンドリーな型 求められる時代になる もしれない

Slide 21

Slide 21 text

No content

Slide 22

Slide 22 text

tsgo/TypeScript 7.0での変化 22 ◎独自プロトコル ら標準のLSPへ移行中[1] While most of the core type-checking code has been ported over without any behavioral differences, the language service is a different story. Given the new architecture, much of the code that powers completions, hover tooltips, navigation, and more, has been heavily rewritten. Additionally, TypeScript 7.0 uses the standard LSP protocol instead of the custom TSServer protocol, so some behavior specific to the TypeScript VS Code Extension may have changed. [2]: Progress on TypeScript 7 – December 2025 | Microsoft, https://devblogs.microsoft.com/typescript/progress-on-typescript-7-december-2025/ Microsoft公式 出したTS 7.0の進捗

Slide 23

Slide 23 text

tsserverの二つのプロセス 23 ○ syntax server: 軽量で、開いてるファイルのタイピング中 ○ semantic server: ホバーやコード補完、ファイル保存時

Slide 24

Slide 24 text

tsgoになった場合(現時点で流動的) 24 ● typescript-language-server 必要無 なる ● 軽量なスレッドを扱える らsyntax/semanticで分けな ていい

Slide 25

Slide 25 text

オーバーロード 一致しない 25 declare function process(x: string, y: number): string; declare function process(x: number, y: string): number; declare function process(x: string[], y: number[]): void; process({}, []); ◎宣言順に試し最後のprocessだけ詳細を表示 ・構造的部分型により、プロパティやメソッド 一致していれば同じ型 ・string[] に必要なメソッド {} には一つも足りないことを説明する …Type '{}' is missing the following properties from type 'string[]': length, pop, push, concat, and 26 more. エラーを出すコード エラーの一部

Slide 26

Slide 26 text

テンプレートリテラル型の直積 26 type Color = "red" | "blue" | "green"; type Size = "sm" | "md" | "lg" | "xl"; type Variant = "solid" | "outline" | "ghost"; type State = "default" | "hover" | "active" | "disabled"; type ClassName = `${Color}-${Size}-${Variant}-${State}`; const cls: ClassName = "purple-xxl-dashed-focus"; ◎軸を1つ増やすと候補数 掛け算で増える →expected側に展開済みユニオン 並んでエラー 伸びる Type '"purple-xxl-dashed-focus"' is not assignable to type '"red-sm-solid-default" | ... 136 more ... | "green-xl-ghost-disabled"'. エラーを出すコード エラーの一部

Slide 27

Slide 27 text

2026年はアプローチ 変わりつつある 28 1 tsgoを使う 2 TypeScript 7.0 で変わること AIフレンドリーに するための工夫 MCPやTools でラップ 3 専用AIモデルを用意する(vercel-autofixer-01)もあったけど割愛...