Repository navigation
Description
The AWS lexicon emits a TypeScript literal union wherever the CloudFormation spec declares AllowedValues, and that works well:
RetentionInDays?: 1 | 3 | 5 | 7 | 14 | 30 | 60 | 90 | 120 | 150 | 180 | 365 | ... | 3653Pass 400 and tsc rejects it and prints the whole valid set in the error. That is the most valuable thing a generated type does for a model or a newcomer: the compiler teaches the API without anyone reading docs.
Where the spec is silent, the property falls back to string, number, or any. That is faithful to the spec, but the spec is silent on a lot, including the properties people touch most.
The surface today
lexicons/aws/src/generated/index.d.ts:
| count | |
|---|---|
| literal-union properties | 1,728 |
bare string |
20,533 |
bare number |
3,162 |
any |
762 |
The part that bites
It is not uniformly sparse — the same property name is typed on one resource and untyped on another, so what the compiler catches depends on which resource you happen to be writing:
InstanceType?: "ml.c4.2xlarge" | "ml.c5.18xlarge" | ... (SageMaker)
InstanceType?: string (58 other resources, incl. EC2)
VolumeType?: "gp2" | "gp3" | "io1" | "io2" | "sc1" | "st1" | "standard"
VolumeType: string
Engine: "aurora" | "aurora_postgresql" | "db2" | "mariadb" | ...
Engine: string
RetentionInDays?: 1 | 3 | 5 | ... | 3653
RetentionInDays?: number
ProtocolType?: any
AWS::EC2::Instance.InstanceType — plausibly the single most-written property in AWS — is string. SageMaker's is a union. Nothing about that ordering is defensible from a user's point of view, and it makes the type system's helpfulness feel arbitrary.
Why it is worth doing
A wrong enum value currently survives tsc and chant build, and fails at deploy — the most expensive tier there is. Every value moved into a union relocates that failure to the cheapest tier, which is the whole argument for a typed substrate over a stringly-typed one.
AWS CDK's L2 constructs hand-write enums well past what the CFN spec carries (ec2.InstanceType, ec2.InstanceClass, ec2.InstanceSize), so this is the specific axis where a spec-faithful generator loses to a hand-curated one, and the gap is closeable without giving up generation.
It matters double for agent authoring: an agent writing chant has read a great deal of CloudFormation and none of chant, so the union in an error message is the cheapest teaching channel available — no docs fetch, no MCP round trip, no extra tokens.
Shape of a fix
Not "hand-write 20,533 types". Suggested order:
- A curated overlay keyed by CFN type + property, merged over the generated output, so a hand-added enum survives the next spec refresh instead of being overwritten by it. The refresh path already exists (feat(aws): upgrade to latest spec #1423 / lexicon-aws v0.40.0).
- Seed the overlay from a better source than the spec where one exists — botocore/service-2.json carries enum shapes the CFN spec omits, and is machine-readable.
- Start with the highest-traffic properties rather than by count — EC2
InstanceType, EBSVolumeType, RDS/ElastiCacheEngineandEngineVersion, DynamoDBBillingMode, S3StorageClass. - Kill the 762
anys separately.ProtocolType?: anyis worse thanstring: it disables checking rather than merely widening it, and it is a small enough set to sweep. - Report coverage as a number in the lexicon build, so it can be watched rather than rediscovered.
Widening a type is backwards-compatible; narrowing string to a union is not, so this wants to land with a lexicon minor bump and a note about what newly fails to compile. Anything the overlay narrows should be a value that was already invalid at deploy.
Where it came from
Found while assessing how chant would place in a pre-registered benchmark comparing typed intent-level constructs against raw HCL for AI-assisted IaC, whose headline metric is tokens-to-green and whose first planted "catch" is an enum value-trap — retention_in_days outside the allowed set. chant catches that one at compile time today. It would not catch the same class of error on InstanceType.
Activity
test: catalogue the enum-overlay refresh script's egress (#1497)
feat(aws): a curated enum overlay, so the highest-traffic properties …