I have an array in TypeScript that looks like this:
const baseElements: IBaseElement[]
An IBaseElement
contains some information:
export interface IBaseElement{
a: number;
b: string;
}
There are two classes that implement the IBaseElement
interface:
export class A implements IBaseElement{
}
export class B implements IBaseElement{
}
The classes A
and B
are stored in the baseElements
array (baseElements.push(A)....
)
While using instanceof
, I can determine if the element is of type A
or B
. However, when the data is serialized to JSON and saved in a database, my concern arises.
My question is, will I be able to distinguish between the two types when retrieving the data from the database?
If there are any areas where my question lacks clarity, please inform me. Thank you in advance.