POV
POV

Reputation: 12005

How to realise generic abstract class?

I have abstract class:

abstract class AScore<T> {
  constructor(
    protected data: T) {}
}

I implement this class like:

class GetActivitiesPupil implements AScore<number> {}

Compiler says it is wrong implementation of class

Upvotes: 2

Views: 44

Answers (1)

Ben Smith
Ben Smith

Reputation: 20230

You want to extend the abstract class to create a concrete instance i.e.

abstract class AScore<T> {
  constructor(protected data: T) {}
}

class GetActivitiesPupil extends AScore<number> {
  data: number;

  constructor(data: number) {
   super(data)}
  }
}

const test = new GetActivitiesPupil(123);
console.log(test.data) // Outputs 123

You can see that this code has no errors here.

Upvotes: 3

Related Questions