Skip to content

Complex Union Types with Special Characters Need Better Sanitization #191

@houstonhaynes

Description

@houstonhaynes

When TypeScript enums or union types contain special characters (like @, /, -), Glutinum generates F# identifiers that either need backticks or fail compilation. Better sanitization with [<CompiledName>] would improve ergonomics.

Example (from CloudflareFS Management API generation)

// TypeScript enum with special characters
type VectorizePreset =
    | "@cf/baai/bge-small-en-v1.5"
    | "openai/text-embedding-ada-002"

Current Behavior (Hawaii, similar pattern)

type VectorizePreset =
    | [<CompiledName "@cf/baai/bge-small-en-v1.5">] @cfBaaiBgeSmallEnV1Numeric_5
    // ^ Invalid F# identifier starting with @

Proposed Improvement

type VectorizePreset =
    | [<CompiledName "@cf/baai/bge-small-en-v1.5">] CfBaaiBgeSmallEnV15
    | [<CompiledName "openai/text-embedding-ada-002">] OpenAiTextEmbeddingAda002

Sanitization Rules

  1. Remove leading special characters
  2. Convert /, -, . to word boundaries for PascalCase
  3. Remove numeric suffixes that can't be in identifiers
  4. Always use [<CompiledName>] to preserve original value

CloudflareFS Workaround

Manual post-processing scripts that:

  1. Detect problematic identifiers
  2. Add backticks where needed
  3. Fix pattern matching to use consistent escaping

Metadata

Metadata

Assignees

No one assigned

    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