Say I have this generic interface:
interface IProcessor<T>{
process(param:T):T;
}
And it's implemented like this:
interface User{
name:string;
}
class WebProcessorImplementation implements IProcessor<User>{
process(param: User): User {
console.log(`process user`);
return {
name:"User"
}
}
}
If I want to use an array of that generic interface, I get the complaint:
class Coordinator {
processors:IProcessor[] //Generic type 'IProcessor<T>' requires 1 type argument(s).ts(2314)
}
Is there a way to tell Typescript everything will be ok here and that we will be passing it full implementations of this interface and the type parameter is not needed? I'm open to other approaches to solve my use case.
IProcessor<T>for someTI don't know"? For example, say you have a valuecof typeCoordinator... What can you pass toc.processors[0].process()?IProcessor<T>interface needs to be fleshed out so that someone could do something with an instance of it without needing to know whatTis. For example,{ process(param:T):T; initialValue(): T}would at least mean that someone could callsomeProcessor.process(someProcessor.initialValue())without knowingT.process()doesn't return a generic, but a standard type defined in my app. Each interface implementation is now responsible for processing its own data and returning it in a common format.