cloudflare / workers-sdk

⛅️ Home to Wrangler, the CLI for Cloudflare Workers®
https://developers.cloudflare.com/workers/
Apache License 2.0
2.56k stars 659 forks source link

🚀 Feature Request: Do TypeScript type checking on `wrangler deploy` #6321

Open ramesaliyev opened 1 month ago

ramesaliyev commented 1 month ago

Describe the solution

Hello!

Wrangler uses esbuild for bundling and since esbuild does not do any type checking (see evanw/esbuild#1631) no errors are produced if there is something wrong. This kinda defeats the purpose.

From esbuild's documentation on TypeScript:

However, esbuild does not do any type checking so you will still need to run tsc -noEmit in parallel with esbuild to check types. This is not something esbuild does itself.


I believe tsc --noEmit or something else needs to be a part of wrangler deploy. Or at least this information, and a solution, should be added to somewhere in documentation. Maybe somewhere in Bundling .

Because I only noticed this by chance. There may be some people out there who are not aware of this.


I'll post my current solution in case someone else needs it.

I've added a custom build to my wrangler.toml which basically does this.

[build]
command = "tsc --noEmit"
cwd = "."
watch_dir = "."
threepointone commented 1 month ago

I'd push back against this. It's not wrangler's purview to enforce type checking (should it fail? warn? should it support all of tsc's flags? etc etc.) That said, maybe the templates generated could include an npm script entry that calls tsc --no-Emit? dunno.

That said, the issue you pointed out with kv-asset-handler seems not directly related. Could you expand on that more? typechecking is failing in the workers-sdk repo for you? Or in a generated app?

ramesaliyev commented 1 month ago

Yeah maybe my wording is a little bit off here. What I actually meant is that when I generate a worker app with typescript by using npm create cloudflare, the generated app should do type checking before deployment. This can be achieved adding custom builds entry to generated wrangler.toml which performs tsc --noEmit like you said.

About the second issue, just ignore it, it was my fault, edited the original issue.

petebacondarwin commented 1 month ago

We are considering adding a wrangler check command that would do type checking (among other things). We could then consider whether a C3 template would run this before wrangler deploy if the user is actually using TypeScript...