You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
I would like to use the types in your library to describe the interfaces in our application to consume them in the backend and frontend libraries.
Currently, I have an issue with optional attributes that are not allowed by the index signature of the { [k: string]: JSON.Value } which is used by the SingleResourceDoc, CollectionResourceDoc and AttributesObject interfaces.
Following a simplified and JSON:API compliant use case:
This scenario would lead to the following typescript error:
TS2344: Type '{ mandatory_property: string; optional_property?: string | undefined; }' does not satisfy the constraint '{ [k: string]: Value; }'.
Property 'optional_property' is incompatible with index signature.
Type 'string | undefined' is not assignable to type 'Value'.
Type 'undefined' is not assignable to type 'Value'.
As described in the JSON:API specification (json-schema), attributes has to be an object which may contain properties with a naming scheme which matches the pattern ^[a-zA-Z0-9](?:[-\\w]*[a-zA-Z0-9])?$ and are not named relationships, links, id or type.
"attributes": {
"description": "Members of the attributes object (\"attributes\") represent information about the resource object in which it's defined.",
"type": "object",
"patternProperties": {
"^[a-zA-Z0-9](?:[-\\w]*[a-zA-Z0-9])?$": {
"description": "Attributes may contain any valid JSON value."
}
},
"not": {
"anyOf": [
{"required": ["relationships"]},
{"required": ["links"]},
{"required": ["id"]},
{"required": ["type"]}
]
},
"additionalProperties": false
},
Describe the solution you'd like
I would appreciate the support for optional attributes or an example of how to use them. Sadly I am not aware of how to change the interface signature to support optional attributes so I am not able to provide a PR at the moment.
Describe alternatives you've considered
I tried to pass different specifications to the generic to support optional attributes but the index signature always wins as expected.
Additional context
The text was updated successfully, but these errors were encountered:
Is your feature request related to a problem? Please describe.
I would like to use the types in your library to describe the interfaces in our application to consume them in the backend and frontend libraries.
Currently, I have an issue with optional attributes that are not allowed by the index signature of the
{ [k: string]: JSON.Value }
which is used by theSingleResourceDoc
,CollectionResourceDoc
andAttributesObject
interfaces.Following a simplified and JSON:API compliant use case:
Example response body 1:
Example response body 2:
Expected interface specification:
This scenario would lead to the following typescript error:
As described in the JSON:API specification (json-schema),
attributes
has to be an object which may contain properties with a naming scheme which matches the pattern^[a-zA-Z0-9](?:[-\\w]*[a-zA-Z0-9])?$
and are not namedrelationships
,links
,id
ortype
.Describe the solution you'd like
I would appreciate the support for optional attributes or an example of how to use them. Sadly I am not aware of how to change the interface signature to support optional attributes so I am not able to provide a PR at the moment.
Describe alternatives you've considered
I tried to pass different specifications to the generic to support optional attributes but the index signature always wins as expected.
Additional context
The text was updated successfully, but these errors were encountered: