0

So I'm trying to create an object which has an arreay of projects I want projects to be a generic of but I'm getting error unresolved type T:

export class AllocationInvestorVO {
    public name: string;
    public id: string;
    public projects: Array<T>; //ERROR: unresolved type T
}

What I am aiming for is the polymorphism behavior we see in Java, that we can create a List object which can be extended to ArrayList for example:

How to Create an Array that Base type is for example Project and it can be polymorphed into Array of type ProjectX or ProjectY.

1 Answer 1

1

If you want the projects to be generic then you need to first declare the AllocationInvestorVO class as generic:

export class AllocationInvestorVO<T> {
    public name: string;
    public id: string;
    public projects: Array<T>; // ok
}

Otherwise T can't be resolved.
If you want to have a base for this T then:

export class AllocationInvestorVO<T extends Project> {
    public name: string;
    public id: string;
    public projects: Array<T>;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.