I have a class which implements an interface. Both define a method which takes in a generic and outputs an Array of the same type as the generic. I'm getting a weird error about inconsistencies between the class and the interface and I'm not sure how to solve it. Here is some sample code:
class Random implements IRandom {
generateArray<T>(method: string): Array<T>;
generateArray<T>(Constructor: new () => T): Array<T>;
generateArray(method: any) {
return new Array<any>();
}
}
interface IRandom {
generateArray<T>(method: string): Array<T>;
generateArray<T>(Constructor: new () => T): Array<T>;
}
Here is an error snippet for the above code:
Class Random declares interface IRandom but does not implement it:
Types of property 'generateArray' of types 'Random' and 'IRandom' are incompatible:
Call signatures of types '{ <T>(method: string): T[]; <T>(Constructor: new() => T): T[]; }' and '{ <T>(method: string): T[]; <T>(Constructor: new() => T): T[]; }' are incompatible:
Types of property 'concat' of types '{}[]' and 'T[]' are incompatible:
Call signatures of types '{ <U extends T[]>(...items: U[]): {}[]; (...items: {}[]): {}[]; }' and '{ <U extends T[]>(...items: U[]): T[]; (...items: T[]): T[]; }' are incompatible:
Types of property 'pop' of types '{}[]' and 'T[]' are incompatible:
Call signatures of types '() => {}' and '() => T' are incompatible.
Has anyone encountered this error? Is there a way to fix it?