ftrackhq / ftrack-ts-schema-generator

Gets the schema from an ftrack instance and generates typescript interfaces for all the entity types in the instance.
Apache License 2.0
2 stars 1 forks source link

bug: parent is typed wrong #20

Open ffMathy opened 1 year ago

ffMathy commented 1 year ago

Instead of typing parent as Context, it should be typed as Omit<Context, "__entity_type__">.

Currently, it can't be set to anything that extends from Context, due to this.

I couldn't find the right place to set this in the code. Is that because this is set dynamically?

gismya commented 1 year ago

There are some issues with type inheritance due to "philosophical" differences between how it works in the Python stack we use (Not what I'm working with, so don't know the exact details). Context in the API means anything that is a context or that inherits fromContext, and the incorrect typing here is one of the issues that this creates.

I think something similar to AddBasicLinkType to correct for this might be the easiest way to fix this.

ffMathy commented 1 year ago

Thank you.

But isn't Context also correct then, but without the __entity_type__ property?

Just need to make sure I understand what you mean and are proposing.

gismya commented 1 year ago

Context is more narrow than what is, in reality, returned (Or expected, on create/update). The most obvious place that this type of behaviour shows is Assignments.Resource for tasks, which is typed as Resource, but in reality is a User (Which is extended from BaseUser which is extended from Resource), which means we have to cast the resource to User to access the properties on it. We don't have a good solution to this, and all the solutions I tried creating quickly became convoluted messes that still didn't work completely.

But Omit<Context, "__entity_type__"> would be better than what's there today, if we can generalize it even further ut would be even better

ffMathy commented 1 year ago

I see. Where would I look to contribute for this, if we go with Omit for now?