-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hono のクライアントの補完を高速化 #19
Conversation
@@ -11,7 +11,8 @@ | |||
"migrate": "drizzle-kit generate && wrangler d1 migrations apply scrap", | |||
"migrate:remote": "drizzle-kit generate && wrangler d1 migrations apply scrap --remote ", | |||
"lint": "biome check", | |||
"lint:fix": "biome check --fix" | |||
"lint:fix": "biome check --fix", | |||
"watch:server-types": "tsc -b -w ./src/server" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ソースコードを更新したら再コンパイルが必要なので、tsc --watch
で更新が必要です
"composite": true, | ||
"declaration": true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
project reference の設定に必須です
https://www.typescriptlang.org/docs/handbook/project-references.html#composite
"declarationMap": true, | ||
"emitDeclarationOnly": true, | ||
"outDir": "./types", | ||
"rootDir": "../" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
サーバーのコードが src/db
など、親ディレクトリのものを参照するので必要です
"paths": { | ||
"@/*": ["./src/*"] | ||
}, | ||
"skipLibCheck": true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
依存パッケージで型エラーが起きたりするので、チェックを無効化
}, | ||
"noUncheckedIndexedAccess": true | ||
} | ||
"disableSourceOfProjectReferenceRedirect": true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
project reference とこのオプションを有効化すると、型情報はコンパイルした *.d.ts
を参照するようになる。
詳しくは以下の PR のコメントを参照。
@@ -2,7 +2,7 @@ | |||
"name": "scrap", | |||
"type": "module", | |||
"scripts": { | |||
"dev": "vite dev", | |||
"dev": "concurrently -r -k yarn:watch:server-types vite", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-r, --raw
は余計な prefix などを付けない、-k, --kill-others
はどれかが終了したら全て終了させる。
|
問題なさそう |
src/server/tsconfig.json
Outdated
"declaration": true, | ||
"declarationMap": true, | ||
"emitDeclarationOnly": true, | ||
"outDir": "./types", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hono のドキュメントにもあるとおり、型を事前にコンパイルするとクライアントの補完が早くなる。
TypeScript の Project References を使う方法を採用した。
https://hono.dev/docs/guides/rpc#compile-your-code-before-using-it-recommended
設定は面倒ですが、これくらい爆速になります。
fast-hono.mov
詳細はコメントで補足します。