🚀 Feature Request: Add a command to check that the generated types are in sync
Describe the solution
In my CI job, I'd like to have a check that the worker-configuration.d.ts file is actually in sync with the worker configuration (i.e. that devs changing the configuration don't forget to run npm run cf-typegen) so that typescript type checking can be relied on.
I attempted to create a GHA job running npm run cf-typegen to regenerate the file and then using https://github.com/marketplace/actions/verify-changed-files to make the job fail if the file is modified. However, this fails because the output of wrangler types is not reproducible. The output contains a comment with the timestamp of the generation run so the file would be modified all the time in my CI job.
I see 2 ways to solve that:
- provide a dedicated check mode in
wrangler types(for instancewrangler types --check) which would compare the existing file content with the generated content with special logic to ignore changes in the timestamp, and report differences by a failure exit code - provide a way to make the
wrangler typesoutput reproducible (either always or with a dedicated flag) by removing the timestamp, which would allow to use existing tooling checking for modified files after running it again.
This sounds like it would be caught by just running tsc. If your Worker code does not match your generated types, then tsc will error. Perhaps you can try running that in your CI job?
We did talk about a wrangler types --check command recently, but we reasoned that all it would be doing is:
- Run
wrangler types. - Run
tsc.
Regenerating the wrangler types before doing typechecking in CI could work to ensure that tsc uses the right type declarations in CI, but this would still create confusion for other devs in the team which would see typescript errors locally.
I already have a CI job running tsc in CI.
However, my goal is to enforce that the version-controlled worker-configuration.d.ts matches the version-controlled wrangler.toml
Note that my request for wrangler types --check is not for it to run type checking on the whole project. It is to check whether the generated worker-configuration.d.ts matches what wrangler types would generate based on the current wrangler.toml.
And if the type generation were reproducible, I would already be able to check that by running wrangler types followed by git status (or a similar git-based detection). My blockage is that wrangler types is not reproducible due to the generation timestamp included in the comment.
@stof this should be fixed by https://github.com/cloudflare/workers-sdk/pull/6329, which will make wrangler types reproducible
great news. This would indeed solve my need.