Is it possible to inline initialize an array of the interface type IFooFace with different specific implementations? Or is it not possible and I have to initialize my objects before the array and then just pass them in?
This is how I can do it in C#:
public interface IFooFace
{
int Id { get; }
}
public class Bar : IFooFace
{
public int Id { get; set; }
public string Name { get; set; }
}
public class Zar : IFooFace
{
public int Id { get; set; }
public string MegaName { get; set; }
}
internal class Program
{
public static IFooFace[] Data =
{
new Bar
{
Id = 0,
Name = "first"
},
new Zar
{
Id = 1,
MegaName = "meeeega"
}
};
}
And this is what I tried in TypeScript:
export interface IFooFace {
id: number;
}
export class Bar implements IFooFace {
public id: number;
public name: string;
// a lot of more properties
}
export class Zar implements IFooFace {
public id: number;
public megaName: string;
// a lot of more properties
}
var Data : IFooFace[] = [
// how to initialize my objects here? like in C#?
// this won't work:
// new Bar(){
// id: 0,
// name: "first"
// },
// new Zar() {
// id: 1,
// megaName: "meeeeega"
// }
// this also doesn't work:
// {
// id: 0,
// name: "first"
// },
// {
// id: 1,
// megaName: "meeeeega"
// }
];