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
There are often models defined as a set of fields plus an additionalProperties of various types, such as object. For example, here is the schema for a ProblemDetails model which is a representation of the RFC 7807 error response body:
That is, the object has fields type, title, status, detail, instance, and can have additional properties of type object. ng-openapi-gen generates this model from the above schema:
ERROR in src/app/api/models/problem-details.ts:3:3 - error TS2411: Property 'detail' of type 'string | null | undefined' is not assignable to string index type '{}'.
3 detail?: null | string;
~~~~~~
src/app/api/models/problem-details.ts:4:3 - error TS2411: Property 'instance' of type 'string | null | undefined' is not assignable to string index type '{}'.
4 instance?: null | string;
~~~~~~~~
src/app/api/models/problem-details.ts:5:3 - error TS2411: Property 'status' of type 'number | null | undefined' is not assignable to string index type '{}'.
5 status?: null | number;
~~~~~~
src/app/api/models/problem-details.ts:6:3 - error TS2411: Property 'title' of type 'string | null | undefined' is not assignable to string index type '{}'.
6 title?: null | string;
~~~~~
src/app/api/models/problem-details.ts:7:3 - error TS2411: Property 'type' of type 'string | null | undefined' is not assignable to string index type '{}'.
7 type?: null | string;
~~~~
This is because the indexer is only typed to the additionalProperties type. It also has to union in all the types of the other fields (or else just switch to any with a warning?):
This won't be trivial to implement, but let's see.
Anyway, I'm still in vacations, and there is surely a pile of work to do when I'm back, so I can't set an ETA.
Cool, have a good vacation! If adding this scenario to the any branch is easier to implement than calculating the proper union type, that would be an acceptable intermediate solution. Maybe with a warning?
There are often models defined as a set of fields plus an
additionalProperties
of various types, such asobject
. For example, here is the schema for aProblemDetails
model which is a representation of the RFC 7807 error response body:That is, the object has fields
type
,title
,status
,detail
,instance
, and can have additional properties of typeobject
.ng-openapi-gen
generates this model from the above schema:Unfortunately this doesn't compile:
This is because the indexer is only typed to the
additionalProperties
type. It also has to union in all the types of the other fields (or else just switch toany
with a warning?):The text was updated successfully, but these errors were encountered: