Skip to content

Add --enum-style const to CLI types and generate #2071

Closed

Description

@ChiragAgg5k

Tracks PR #2070.

Plan

Goal

Let appwrite types (TypeScript) and appwrite generate emit enum columns as an as const object plus a same-named union type, behind an opt-in --enum-style enum|const flag. enum is not erasable syntax: generated .ts files currently fail tsc --erasableSyntaxOnly (TS1294) and Node's type stripping refuses them (ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX). Default stays enum, so existing output does not change. Fixes appwrite/sdk-for-cli#277.

What changes (from the PR diff)

  • templates/cli/internal/typegen/enum_style.go (new): EnumStyle type (enum, const), EnumStyleChoices(), ParseEnumStyle() which rejects unknown values.
  • templates/cli/internal/typegen/typescript.go: shared TypeScript.DeclareEnum renderer with EnumStyle and Declaration options. For .d.ts, .d.mts and .d.cts destinations the const style emits export declare const X: { readonly ... }, because an ambient const can't take an object initializer (TS1254).
  • templates/cli/internal/cmd/types.go: --enum-style flag. runTypes parses it, rejects const for non-TypeScript languages, and sets Declaration from the destination's extension.
  • templates/cli/internal/cmd/generate.go, templates/cli/internal/generator/generator.go, templates/cli/internal/generator/typescript.go: --enum-style flag and Options.EnumStyle. generateEnums now uses typegen.TypeScript.DeclareEnum in place of its own enum printer.
  • src/SDK/Language/CLI.php: copies the new enum_style.go and the three new golden files into the generated CLI.
  • Tests: internal/typegen/language_test.go with goldens ts.const.appwrite.ts and ts.const.appwrite.d.ts; internal/generator/generator_test.go with golden server.const.types.ts; internal/cmd/typegen_commands_test.go covering the flag surface, the enum default, and rejection of unknown and non-TS values.

Remaining steps

  1. Get review on feat(cli): add --enum-style const to types and generate #2070 and address any feedback. The PR is the whole code change.
  2. Merge, then ship it in the next CLI release (regenerate appwrite/sdk-for-cli) and close TypeScript enums sdk-for-cli#277.
  3. Mention --enum-style const in the CLI docs and changelog for types and generate.

Risks

  • Default enum output has to stay byte-for-byte identical. The existing golden files guard this.
  • A consumer switching to const may rely on enum-only behaviour such as reverse mapping or enum-typed declarations merging. The flag is opt-in, so only people who choose it are affected.

Done when

Activity

  1. self-assigned this
    on Oct 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions