#Type inclusion constraints in closed records

1 messages · Page 1 of 1 (latest)

light shell
#

Hi Team,

I have the following record defined with type inclusion;

public type CustomCodeableConcept record {|
    *core:CodeableConcept;

    core:Coding[] coding?;
    CustomCodingType[] v2Coding;
    string id?;
    string text?;
|};

Record definition of CodeableConcept in core package;

public type CodeableConcept record {|
    *Element;
    string id?;
    Coding[] coding?;
    string text?;
|};

When the CustomCodingType[] v2Coding; is added to the record, it does not get identified as a subtype of CodeableConcept core type.

Am I doing something wrong here, or is there any workaround to get this resolved?

#

Example scenario:
Getting and error included field 'type' of type 'myorg/core.CodeableConcept:1.0.0' cannot be overridden by a field of type 'customorg/custom:1.0.0:CustomCodeableConcept': expected a subtype of 'myorg/core:1.0.0:CodeableConcept'

for the following code,

public type CustomIdentifier record {|
    *core:Identifier;

    r4:Extension[] extension?;
    core:Period period?;
    core:Reference assigner?;
    string id?;
    CustomCodeableConcept 'type;
    string value;
|};

Type definition of core:Identifier type

public type Identifier record {|

    *Element;
    string id?;
    Extension[] extension?;

    CodeableConcept 'type?;
    string value?;
    Period period?;
    Reference assigner?;
|};
opaque ridge
#

As indicated by the error message, when overriding an included field, the type of the overriding field should be a subtype of the type of the overridden field.

Simple example,

type Identifier record {|
    string|int id;
    string name;
|};

type StringIdentifier record {|
    *Identifier;
    string id; // OK
|};

type AnydataIdentifier record {|
    *Identifier;
    anydata id; // Error
|};

Therefore, in your example, CustomCodeableConcept should be a subtype of CodeableConcept. Simplifying the records you've shared

public type CodeableConcept record {|
    *Element;
    string id?;
    Coding[] coding?;
    string text?;
|};

public type CustomCodeableConcept record {|
    *CodeableConcept;
    CustomCodingType[] v2Coding;
|};

Is v2Coding defined in Element? If so, CustomCodingType[] should be a subtype of the type of v2Coding in Element.

If not, since CodeableConcept is a closed record, and CustomCodeableConcept has an additional field that is not defined in CodeableConcept, CustomCodeableConcept is not a subtype CodeableConcept, which results in this error.

#

If it is the latter, and CodeableConcept is meant to be extended with additional fields like you've done with CustomCodeableConcept, you could consider making CodeableConcept and open record.

public type CodeableConcept record {
    *Element;
    string id?;
    Coding[] coding?;
    string text?;
};