microsoft/fhir-codegen

TypeScript_R4.ElementDefinitionExample values all mandatory

djehring opened this issue · 1 comments

In the generated TypeScript_R4 the interface generation of ElementDefinitionExample has all the values (valueCode, valueBoolean etc) as mandatory so that the typescript checking fails when you try and instantiate an ElementDefinition with an example e.g
"example": [ { "valueUri": "http://hl7.org/fhir/v3/MaritalStatus", "label": "General" } ],
then the TypeScript type checking fails. This will be because the profile says that value[x] must have a value but there is no way to represent in an interface that I am aware of to say it must have only one of the multiple types of values that are allowed. If you mark them all as optional then it will type check correctly but not sure how your codegen could evaluate this pattern

Apologies for the delay in closing the issue - I was tracking this via discussion on Zulip and missed the open issue here.

The change was made to move choice elements to optional and forgo any run-time checking that at least one is present. It's the "most correct" model we could come up with for now. I am open to adding run-time checking in the future (e.g., via io-ts or ts.data.json), but it would likely split from these as it carries a heavy performance penalty.

If you have any additional feedback, please let me know.