Skip to main content

Overview

The CLI generates TypeScript types or Go accessors from the local flag config. TypeScript output defaults to src/generated/flags.ts. Pass its FlagDefinitions type to the SDK and flag keys, variant names, and value types are checked at compile time. A misspelled key fails the build instead of silently serving a default.

Generated output

The exact shape is in Generated types.

When it is written

Types always come from the local flag config, never from the server. To write somewhere else, set typesOut in .shipd/config.json:

Commit it

Commit src/generated/flags.ts alongside shipd.config.ts. Your app then type-checks on a fresh clone and in CI without running the CLI first, and pull requests show type changes next to flag changes.
  • Never edit it by hand. The next push, pull, or shipd types gen overwrites it.
  • If it drifts from shipd.config.ts, run shipd types gen and commit the result.
  • To catch drift in CI, run shipd types gen and fail on git diff --exit-code src/generated/flags.ts.

Use generated output with the SDK

Pass FlagDefinitions as the TypeScript client type argument, or import your module’s generated Go flags package.
For React, create the typed bindings once:
src/flags.ts (React)
Without the type argument, any string is accepted as a key.

Go output

Set typesLanguage: "go" and typesPackage: "flags" in project settings to generate Go after push and pull too. Go output defaults to internal/flags/flags_gen.go. The Go output above uses the four flags from the Go tutorial. The generator creates one accessor per flag, its key constant, a Defaults() function, and named string types and constants for variants. Misspelled accessor names and incompatible return types fail compilation. Go variant types are named strings, so Go still permits explicit conversions from arbitrary strings; they are not closed unions. JSON stays any because the served payload can change shape. Flag keys become exported Go names (new-checkout → NewCheckout). Identifier collisions such as new-checkout and new_checkout, including collisions with generated variant constants, fail generation with a validation error. Rename the conflicting flag or variant. Commit internal/flags/flags_gen.go alongside the config. Check drift with:

What a mistake looks like

Output
The same check catches reading a flag with the wrong method (shipd.isEnabled("search-variant")) and comparing against a variant that does not exist (shipd.getVariant("search-variant") === "v3").

Next steps