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
In typescript-fetch, this gets generated to multiple "oneOf". The one Schedule having the "Yearly" property is translated to the following class:
exportinterfaceScheduleOneOf{/** * * @type {YearlySchedule} * @memberof ScheduleOneOf */Yearly: YearlySchedule;}/** * Check if a given object implements the ScheduleOneOf interface. */exportfunctioninstanceOfScheduleOneOf(value: object): boolean{if(!('Yearly'invalue))returnfalse;returntrue;}exportfunctionScheduleOneOfFromJSON(json: any): ScheduleOneOf{returnScheduleOneOfFromJSONTyped(json,false);}exportfunctionScheduleOneOfFromJSONTyped(json: any,ignoreDiscriminator: boolean): ScheduleOneOf{if(json===undefined||json===null){returnjson;}return{'Yearly': YearlyScheduleFromJSON(json['Yearly']),};}exportfunctionScheduleOneOfToJSON(value?: ScheduleOneOf|null): any{if(value===undefined){returnundefined;}if(value===null){returnnull;}return{'Yearly': YearlyScheduleToJSON(value['Yearly']),};}
Working with these oneOf is extremly frustrating, since I have to run a huge if else blocks to figure out which oneOf it actually is and have to parse it. This is one very simple example:
const as{{classname}} = (oneOf: {{superclassname}}): {{classname}} | null => {
if (instanceOf{{classname}}(oneOf) && <for each required property (oneOf as {{classname}}).{{property}} !== undefined)> {
return oneOf as {{classname}};
}
return null;
}
my life would be so much easier and I need to write so much less code.
Describe alternatives you've considered
As an alternative the already existing instanceOfScheduleOneOf isn't much of help here. Since it only check if the interface is satisfied and not if the required values aren't undefined.
The text was updated successfully, but these errors were encountered:
and pass this to ScheduleToJSON inside the update call auto-generated by typescript-fetch, I will allways receive {} since instanceOfScheduleOneOf checks for 'Yearly' in value - which is true. Now it gets passed to ScheduleOneOfToJSON which tries to
Is your feature request related to a problem? Please describe.
Imagine this schema
In typescript-fetch, this gets generated to multiple "oneOf". The one Schedule having the "Yearly" property is translated to the following class:
Working with these
oneOf
is extremly frustrating, since I have to run a hugeif else
blocks to figure out whichoneOf
it actually is and have to parse it. This is one very simple example:Describe the solution you'd like
If there was just one simple helper function in each
oneOf
class like the following:or in "pseudo code"
my life would be so much easier and I need to write so much less code.
Describe alternatives you've considered
As an alternative the already existing
instanceOfScheduleOneOf
isn't much of help here. Since it only check if the interface is satisfied and not if the required values aren't undefined.The text was updated successfully, but these errors were encountered: