-
Notifications
You must be signed in to change notification settings - Fork 36
fix(typescript): optional scalar fields lose their optional modifier #194
Description
Description
When generating TypeScript code from a Concerto model, optional fields that use a scalar type lose their optional modifier (?).
Steps to Reproduce
Create a model with an optional scalar field and generate TypeScript:
Model: namespace org.example@1.0.0 scalar MyString extends String concept Person { o MyString nickname optional }
Command: concerto generate --model model.cto --target typescript
Expected vs Actual
Expected: nickname?: string;
Actual: nickname: string; (missing ?)
Root Cause
In lib/codegen/fromcto/typescript/typescriptvisitor.js, the visit() method calls this.visitField(thing.getScalarField(), parameters) for scalars. The scalar field doesn't inherit the parent's optional property.
Proposed Fix
Pass forceOptional via parameters instead of mutating the scalar field, then honor it in visitField().
Related
- This bug was discovered via a TODO comment in
accordproject/concertoatpackages/concertino/scripts/generateTypes.js:119which implemented a local workaround. Once this fix is merged, that workaround can be removed.