Repository navigation
Generate binding types from API documentation - #316
Merged
Merged
Conversation
Callers of another app's API wrote the binding's type by hand, because
they do not have the provider's source for Cloudflare's `Service<T>`.
The compiler could not notice when the provider changed a method, and
generated APIs with hundreds of generic methods could not be copied.
`GET /api/v1/app-services/{service}/types` turns the active deployment's
documentation into declarations for one entrypoint and binding name, and
`widefleet services types APP --as BINDING` prints or writes them.
`--check` fails when the file no longer matches, for CI.
The binding is a plain interface with each documented signature,
including type parameters and TSDoc, so recursive types stay within the
compiler's instantiation limits. Results are typed as callers receive
them: a question's `requestState` arrives sealed, and `withInput` returns
the methods. Documented types keep their declarations, with field
descriptions on their members. Same-named types from different modules
are named after their modules. References the documentation does not
declare become `unknown`, keep their text in a comment and are listed in
the header.
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
widefleet-docs | 8b2ff52 | Nov 22 2026, 11:32 PM |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
An app that calls another app's API writes the binding's type by hand, for example
INVENTORY: { status(): Promise<{ configured: boolean }> }. Cloudflare'sService<T>needs the provider's source, which the caller does not have. When the provider changes a method, the caller's compiler does not notice; the error appears at runtime. Generated APIs cannot be copied by hand at all: the Linear template has 424 methods with generic selection types.What changes
GET /api/v1/app-services/{service}/types?binding=LINEAR&entrypoint=defaultreturns declarations generated from the active deployment's documentation, with the same authorization as describe.widefleet services types linear --as LINEAR [--entrypoint NAME] [--output FILE] [--check]. Without--outputit prints the file;--checkfails with a usage error when the file differs from the active deployment, so CI notices provider changes, including renamed types. Line endings do not matter.serviceBindingTypesin contracts):Service<T>, so recursive types stay within the compiler's instantiation limits.LINEAR.Result<R>replaces a question'srequestStatewith the sealed string, andwithInput(answer)returns the methods withoutfetch.fetchis declared only for HTTP entrypoints.interfaceortypeby theirkind, with their type parameters, sorted by name so document order does not change the file. Field descriptions move onto their members where the definition is one object type.src_a_record_Entry; a name already taken gains underscores.unknown /* import("…").Token */and are listed in the header.Promise, is refused with a message.shortenTypeNamesand the generator share one reference scanner (rewriteTypeReferences); shortening is unchanged.Why the server generates the file
The documentation format is a storage contract of the platform (format 3) and the sealing of
requestStateis runtime behavior. Generating on the server keeps both in one place, so CLI releases do not depend on the stored format and the API offers the same types to every client. The CLI only downloads, writes and compares. Raw documentation access through the API is not added; no client needs it for this.Verification
pnpm typecheck,oxfmt --check .,oxlint --type-aware --deny-warningson changed files,cargo clippy,cargo test -p platform-core -p platform-cliRUN_CLI_TESTS=1service-binding-types.test.ts: a fixture app with a generic declaration with constraint and default, recursive types, same-named types from two modules, a package class, a question withrequestStateand an HTTP entrypoint is documented by the native extractor, generated, and a caller compiles against it with@tsconfig/strictestandskipLibCheck: false, including@ts-expect-errorcases for constraints, missing arguments, unresolved types andwithInput.app-services-cli.test.ts: printing,--output,--checkwith a matching, CRLF, changed and missing file.app-services.integration.test.ts: undocumented app, unknown entrypoint, taken binding name, other organization.typeof, field descriptions, refused names.templates/linear/tests/types.tscompiles against the generated file with@tsconfig/strictestandskipLibCheck: false, with only its import line changed, including all@ts-expect-errorcases.Documentation: #317 (draft).


Confidence Score: 5/5
The PR appears safe to merge; the previous compilation issue is addressed.Summary
Adds generated TypeScript declarations for app service bindings through the API and CLI.
Reviews (2) · Last reviewed commit: "Reject binding names that cannot name an..." · Reviewed by Greptile