Have you ever wondered about the nature of a type?
All this talk may seem perplexing, but sometimes code speaks louder than words.
// Consider an interface
interface A {
}
// Now, imagine a class that implements this interface.
// There are several implementations of A, but let's focus on AImpl.
class AImpl implements A {
}
// Next, envision a repository that manages these types and identifies the best one.
class Repository {
// This repository method returns the most up-to-date type.
static getTypeForA(): Function {
return AImpl;
}
}
Interesting, right? It returns a Function
while actually returning a class. This setup functions well because a class is ultimately a function.
But wait, isn't there a better approach? What type should be chosen for a type?