fix(codegen): change DateTime type to string in TypeScript generation#258
fix(codegen): change DateTime type to string in TypeScript generation#258apoorv7g wants to merge 1 commit into
Conversation
Updated the TypeScript code generation to replace 'Date' with 'string' for DateTime types. This change affects the generated types for ITransaction, IEvent, and IPerson interfaces, as well as the handling of scalar declarations in the TypescriptVisitor class. Updated corresponding tests to reflect these changes. Signed-off-by: Apoorv <130035517+APOORV7G@users.noreply.github.com>
|
Thanks a lot for this PR @apoorv7g! |
|
@mttrbrts can this be merged , this resolves #257 @23harshitkumar would appreciate it. |
|
Great to see the collaboration both! @apoorv7g @23harshitkumar Is there a solution that doesn't require a breaking change? E.g. parsing the ISO string to create TypeScript Date objects? |
|
@mttrbrts the parsing can only happen on the client side i.e. outside |
|
@mttrbrts Yes, I can confirm what @apoorv7g is saying. Since codegen only generates TS interfaces (which vanish entirely at runtime), there's no place to insert parsing logic. To do that, we would need to do some pretty good changes to the codegen. From the Playground side, all contract data flows through JSON, where dates are always ISO strings. Mapping |
fix(typescript): map Concerto DateTime to string in generated types
Closes #257
When generating TypeScript interfaces from Concerto models, the
DateTimeprimitive was mapped to the TypeScriptDatetype. In JSON and at runtime, DateTime values are represented as ISO-8601 strings (for example,"2026-06-27T13:14:00.000Z"). This mismatch caused strict TypeScript compilation errors when logic code assigned values such asnew Date().toISOString()to DateTime fields a common pattern in Template Playground logic files.This PR updates
toTsTypeinTypescriptVisitorto mapDateTimetostring, aligning generated types with how Concerto data is actually serialized and consumed over JSON.Changes
DateTimeprimitive tostringinstead ofDateinTypescriptVisitor.toTsType(lib/codegen/fromcto/typescript/typescriptvisitor.js)Time), and map key/value types (e.g.Map<string, string>instead ofMap<string, Date>)test/codegen/fromcto/typescript/typescriptvisitor.jsfor scalar declarations, map declarations, andtoTsTypetest/codegen/__snapshots__/codegen.js.snapfor affected interfaces (ITransaction,IEvent,IPerson, etc.)Flags
Datewill need to regenerate types and update code that assignsDateobjects directly. JSON-backed workflows (Template Playground, Cicero logic, etc.) are the intended beneficiaries and should require no runtime changes.stringvsDate | string:stringwas chosen deliberately because Concerto JSON serialization always represents DateTime as an ISO-8601 string. A union type would imply both forms are equally common at runtime, which is not the case for JSON payloads.Before (generated TypeScript):
After (generated TypeScript):
Related Issues
Author Checklist
--signoffoption of git commit.mainfromfork:branchname