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/concerto at packages/concertino/scripts/generateTypes.js:119 which implemented a local workaround. Once this fix is merged, that workaround can be removed.
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 typescriptExpected 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'soptionalproperty.Proposed Fix
Pass
forceOptionalvia parameters instead of mutating the scalar field, then honor it in visitField().Related
accordproject/concertoatpackages/concertino/scripts/generateTypes.js:119which implemented a local workaround. Once this fix is merged, that workaround can be removed.