I have been working with Polymorphic relationships and currently have the following TypeScript interface defined:
interface SubjectA {}
interface SubjectB {}
interface SubjectC {}
enum SubjectType {
SubjectA = 'Subject A',
SubjectB = 'Subject B',
SubjectC = 'Subject C',
}
interface ExampleSubject {
type: SubjectType;
subject: SubjectA | SubjectB | SubjectC
}
In this scenario, it is clear that ExampleSubject.subject
can be one of three possible subject types (SubjectA
, SubjectB
, SubjectC
).
My goal is to dynamically resolve its type based on the value of ExampleSubject.type
. For instance, if ExampleSubject.type
is set to SubjectType.SubjectA
, then ExampleSubject.subject
should correspond to SubjectA
.
I would appreciate any guidance on how to achieve this dynamic resolution. Thank you